Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Ports - Heather #32

wants to merge 2 commits into from

Conversation

piffer59
Copy link

No description provided.

@bonara
Copy link

bonara commented Mar 4, 2019

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.
For the times loop, there looks to be two iteration variables compare_1 and compare_2. I think times loop can take one iteration variable that is incremented by one every time the loop runs. We can change the compare variables to i and pass the i as the array index.
One last thing is the return true inside if array1[x] == array2[x] statement. If the first element in both arrays are equal it exits the times loops and returns true. But we need to check if all the elements are equal.

Sorry for the long comment. Hope it helps :)

Copy link

@pmanni02 pmanni02 left a 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
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants