-
Notifications
You must be signed in to change notification settings - Fork 47
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
Ports - Heather #32
base: master
Are you sure you want to change the base?
Ports - Heather #32
Conversation
As you pointed out already, our codes are pretty similar. I didn't include a conditional for empty arrays because it is checked on the last return statement. If match_count == array1.length, it returns true. So for the case when both arrays were empty, the match_count variable wouldn't be incremented as its value increases only when the array elements match. You mentioned that your test for empty array check wasn't passing. I think I see the reason why. The variable x is getting reset to 0 every time the limes loop run. If you move x=0 outside of the times loop, it should get incremented correctly. Sorry for the long comment. Hope it helps :) |
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.
Hello Heather, my name is Phoebe (c9) and I have been assigned to review your PRs. Please let me know if you have any questions on my comments/feedback going forward.
Well done. Overall, you have the logic down. See my comments below for ways you can make your fn more concise.
return false | ||
elsif array1.length != array2.length | ||
return false | ||
elsif array1.length == array2.length |
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.
No need to check the lengths of the array here. If your fn gets to this line you already know the arrays have the same length.
element_count = 0 | ||
array1.length.times do |x| | ||
if array1[x] == array2[x] | ||
element_count += 1 |
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.
Keeping track of element_count
is extra work. If the elements of the arrays (at the same index) are not equal, you should return false right away.
end | ||
|
||
if array1.length == element_count | ||
return true |
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.
At this point, verifying that element_count
equals the length of the first array is an extra check. This conditional (line 21) will always be true. So you can get rid of the check and just return true.
No description provided.