Conversation
| end | ||
|
|
||
| def self.add_element_array(element, array) | ||
| # binding.pry |
There was a problem hiding this comment.
You might want to remove this line before publication.
| array.each do |element| | ||
| flattened_array = self.add_element_array(element, flattened_array) | ||
| end | ||
| flattened_array.compact |
There was a problem hiding this comment.
Replace .compact with .compact! to modify the original array.
There was a problem hiding this comment.
If we added a ! it would return nil if no changes were made, which we might want to avoid
| # binding.pry | ||
| if element.class == Array | ||
| element.each do |ele| | ||
| array = self.add_element_array(ele, array) |
| else | ||
| array << element | ||
| end | ||
| array |
There was a problem hiding this comment.
return array? or do something with array?
|
|
||
| module BookKeeping | ||
| VERSION = 1 # Where the version number matches the one in the test. | ||
| end |
| end | ||
|
|
||
| def self.add_element_array(element, array) | ||
| # binding.pry |
There was a problem hiding this comment.
please remove the comment after debugging!
| flattened_array.compact | ||
| end | ||
|
|
||
| def self.add_element_array(element, array) |
There was a problem hiding this comment.
please change the variables to be more clear to the code( element and array)
| @@ -0,0 +1,28 @@ | |||
| require 'pry' | |||
|
|
|||
There was a problem hiding this comment.
remove the debugging stuff, or comment it out?
| array.each do |element| | ||
| flattened_array = self.add_element_array(element, flattened_array) | ||
| end | ||
| flattened_array.compact |
| # binding.pry | ||
| if element.class == Array | ||
| element.each do |ele| | ||
| array = self.add_element_array(ele, array) |
There was a problem hiding this comment.
Is this recursion necessary? Clever, but I feel that we may be sacrificing too much space.
| array.each do |element| | ||
| flattened_array = self.add_element_array(element, flattened_array) | ||
| end | ||
| flattened_array.compact |
There was a problem hiding this comment.
The .compact method is making a copy here, this method could use a ! (compact!) or be saved to a new variable name with the non-mutating version.
| else | ||
| array << element | ||
| end | ||
| array |
| end | ||
|
|
||
| def self.add_element_array(element, array) | ||
| # binding.pry |
| flattened_array.compact | ||
| end | ||
|
|
||
| def self.add_element_array(element, array) |
There was a problem hiding this comment.
rename method (unclear functionality based on name)
| def self.add_element_array(element, array) | ||
| # binding.pry | ||
| if element.class == Array | ||
| element.each do |ele| |
This method flattens an array