-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pr-8 #9
base: master
Are you sure you want to change the base?
Pr-8 #9
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,28 @@ | ||||||||
require 'pry' | ||||||||
|
||||||||
class FlattenArray | ||||||||
def self.flatten(array) | ||||||||
flattened_array = [] | ||||||||
|
||||||||
array.each do |element| | ||||||||
flattened_array = self.add_element_array(element, flattened_array) | ||||||||
end | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to add a new line here.
Suggested change
|
||||||||
flattened_array.compact | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compact returns a copy of the array which increases space complexity. |
||||||||
end | ||||||||
|
||||||||
def self.flatten(array) | ||||||||
retVal = [] | ||||||||
for item in array | ||||||||
if item == nil | ||||||||
next | ||||||||
elsif item.kind_of?(Array) | ||||||||
retVal += flatten(item) | ||||||||
else | ||||||||
retVal.push(item) | ||||||||
end | ||||||||
end | ||||||||
return retVal | ||||||||
def self.add_element_array(element, array) | ||||||||
# binding.pry | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Consider removing this line if we are wanting to push to prod. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment? |
||||||||
if element.class == Array | ||||||||
element.each do |ele| | ||||||||
array = self.add_element_array(ele, array) | ||||||||
end | ||||||||
else | ||||||||
array << element | ||||||||
end | ||||||||
array | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An explicit return might make this more legible.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. including return would be helpful |
||||||||
end | ||||||||
end | ||||||||
|
||||||||
module BookKeeping | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might just be me, but it's a little hard to understand what this is doing. Could you maybe add a comment for context? |
||||||||
VERSION = 1 # Where the version number matches the one in the test. | ||||||||
end | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a .map instead of .each. This would not require declaring var in line 5.