-
Notifications
You must be signed in to change notification settings - Fork 47
Ports - Kasey #44
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
base: master
Are you sure you want to change the base?
Ports - Kasey #44
Changes from all commits
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,5 +1,18 @@ | ||
| # Determines if the two input arrays have the same count of elements | ||
| # and the same integer values in the same exact order | ||
| def array_equals(array1, array2) | ||
| raise NotImplementedError | ||
| if array1 == nil && array2 == nil || array1 == [] && array2 == [] | ||
| return true | ||
| elsif array1 == nil || array2 == nil || array1.length != array2.length | ||
| return false | ||
| else | ||
| i = 0 | ||
|
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. Nit: this block shouldn't be nested inside an |
||
| array1.each do |x| | ||
|
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. Nit: Would this break if (for whatever reason) |
||
| if x != array2[i] | ||
| return false | ||
| end | ||
| i += 1 | ||
| end | ||
| end | ||
| return true | ||
| end | ||
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.
Good boundary checking!
Style nit: this many
if-statements all in one line is a bit confusing. (You have to know Ruby's order of operations in order to understand it. 😄 )if (array1 == nil && array2 == nil) || (array1 == [] && array2 == []))== niland== []) into separate "guarding"if-statementse.g.
You might even be able to do this - but some people would say this
is not explicit enough (or "has too much magic")