Skip to content

Conversation

@carlabosco
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Your code definitely works, but things are nested very deeply and it could be written much cleaner.

consider

if array1.length != array2.length
  return false
else
  array1.each_with_index do  |element, index|
    return false if element != array2[index]
  end
  return true # must have gone through the entire list and found them all equal
end

Copy link

@ace-n ace-n left a comment

Choose a reason for hiding this comment

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

Tests pass! A few minor style fixes and you should be good to go. 🙂

(Sorry about the duplicate reviews, just realized Chris already covered this.)

end

if array1.length == array2.length
loop_count = array1.length
Copy link

Choose a reason for hiding this comment

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

Tiny style nit: is this extra variable necessary?

loop_count.times do |i|
if array1[i] != array2[i]
return false
else
Copy link

Choose a reason for hiding this comment

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

Style nit: do we need this else block? I have a feeling we can delete it, if we put a return true statement after it.

(returning exits the function - so any code after an executed return statement won't run.)

return false
end

if array1.length == array2.length
Copy link

Choose a reason for hiding this comment

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

Style nit: using a "guarding if" that checks if array1.length does not equal array2.length is probably more readable here. (If nothing else, more programmers are used to that pattern - so it's easier for your coworkers to recognize.)

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.

4 participants