Conversation
lib/array_equals.rb
Outdated
| # and the same integer values in the same exact order | ||
| def array_equals(array1, array2) | ||
| raise NotImplementedError | ||
| if array1 == nil || array2 == nil |
There was a problem hiding this comment.
When I think about how to write effective if-statements, I normally think of the flow like a triangle, where the stricter conditions should be going first, and the less strict conditions follow. The reason is if what you want to check does not meet the stricter conditions, you can quickly return the result without wasting time moving through the rest of the less strict conditions.
Applying the principle above to this particular problem, I will put the && before the | |.
lib/array_equals.rb
Outdated
| return true | ||
| elsif array1 == [] && array2 == [] | ||
| return true | ||
| elsif array1 == nil || array2 == nil |
There was a problem hiding this comment.
The statements on line 9 & 10 seem contradictory to the statement on line 5 & 6. Could you please look into it?
lib/array_equals.rb
Outdated
| return false | ||
| index = 0 | ||
| while index < array_length | ||
| if array1[current_index] != array2[current_index] |
There was a problem hiding this comment.
I think you mean index (instead of current_index) here?
| @@ -2,4 +2,42 @@ | |||
| # and the same integer values in the same exact order | |||
| def array_equals(array1, array2) | |||
| raise NotImplementedError | |||
There was a problem hiding this comment.
Make sure to remove the raise here, otherwise it will throw an exception.
| return true | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
Code is clear, concise and easy to read. Good work!
No description provided.