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 :) |
pmanni02
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.