Skip to content

PR-8#8

Open
CheezItMan wants to merge 1 commit intomasterfrom
PR-#8
Open

PR-8#8
CheezItMan wants to merge 1 commit intomasterfrom
PR-#8

Conversation

@CheezItMan
Copy link
Copy Markdown

This method flattens an array

@tildeee tildeee changed the title Create flatten_array.rb PR-8 Feb 6, 2020
Comment thread flatten_array.rb
end

def self.add_element_array(element, array)
# binding.pry
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to remove this line before publication.

Comment thread flatten_array.rb
array.each do |element|
flattened_array = self.add_element_array(element, flattened_array)
end
flattened_array.compact
Copy link
Copy Markdown

@llinneaa llinneaa Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace .compact with .compact! to modify the original array.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we added a ! it would return nil if no changes were made, which we might want to avoid

Comment thread flatten_array.rb
# binding.pry
if element.class == Array
element.each do |ele|
array = self.add_element_array(ele, array)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of recursion

Comment thread flatten_array.rb
else
array << element
end
array
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return array? or do something with array?

Comment thread flatten_array.rb

module BookKeeping
VERSION = 1 # Where the version number matches the one in the test.
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line at the end!

Comment thread flatten_array.rb
end

def self.add_element_array(element, array)
# binding.pry
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the comment after debugging!

Comment thread flatten_array.rb
flattened_array.compact
end

def self.add_element_array(element, array)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the variables to be more clear to the code( element and array)

Comment thread flatten_array.rb
@@ -0,0 +1,28 @@
require 'pry'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the debugging stuff, or comment it out?

Comment thread flatten_array.rb
array.each do |element|
flattened_array = self.add_element_array(element, flattened_array)
end
flattened_array.compact
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the runtime of @compact?

Comment thread flatten_array.rb
# binding.pry
if element.class == Array
element.each do |ele|
array = self.add_element_array(ele, array)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this recursion necessary? Clever, but I feel that we may be sacrificing too much space.

Comment thread flatten_array.rb
array.each do |element|
flattened_array = self.add_element_array(element, flattened_array)
end
flattened_array.compact
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread flatten_array.rb
else
array << element
end
array
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended: make explicit return

Comment thread flatten_array.rb
end

def self.add_element_array(element, array)
# binding.pry
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove binding.pry

Comment thread flatten_array.rb
flattened_array.compact
end

def self.add_element_array(element, array)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename method (unclear functionality based on name)

Comment thread flatten_array.rb
def self.add_element_array(element, array)
# binding.pry
if element.class == Array
element.each do |ele|
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename 'ele'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants