Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
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| end | ||
|
|
||
| if array1.length == array2.length | ||
| loop_count = array1.length |
There was a problem hiding this comment.
Tiny style nit: is this extra variable necessary?
| loop_count.times do |i| | ||
| if array1[i] != array2[i] | ||
| return false | ||
| else |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.)
No description provided.