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 - Mina #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
13 changes: 12 additions & 1 deletion lib/array_equals.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# 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 == [] && array2 == [] || array1 == nil && array2 == nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Technically, comparing with [] relies on the built-in array equality operator. It's also redundant with checking length, since if both arrays are equals to empty arrays, they will both have length of 0. You should be able to safely remove array1 == [] && array2 == [] || .

return true
elsif array1 == nil || array2 == nil || array1.length != array2.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not-actual-feedback industry experience note:

It's not 100% necessary to use elsif and else for this particular set of logic because of the fact that you're returning early. The early return naturally excludes any logic that happens later in the function.

You could argue, and I tend to lean that way, that it's better style (and more future-proof) to keep the if/elsif/else structure, just as you have it. At the same time, you may encounter (as I have at work) some IDEs or tools that enforce removing these clauses from the statements they surround when early returns exist and they're not absolutely necessary.

I wouldn't change what you have, but I thought you'd appreciate knowing that some shops will consider this style "wrong" and some shops will consider this style "right". It's something you'll find out and adapt to when you get there.

return false
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not-actual-feedback industry experience note:

It's not 100% necessary to use elsif and else for this particular set of logic because of the fact that you're returning early. The early return naturally excludes any logic that happens later in the function.

You could argue, and I tend to lean that way, that it's better style (and more future-proof) to keep the if/elsif/else structure, just as you have it. At the same time, you may encounter (as I have at work) some IDEs or tools that enforce removing these clauses from the statements they surround when early returns exist and they're not absolutely necessary.

I wouldn't change what you have, but I thought you'd appreciate knowing that some shops will consider this style "wrong" and some shops will consider this style "right". It's something you'll find out and adapt to when you get there.

array1.length.times do |item|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Using the name item for an array index is a little confusing. If I'm reading this quickly, I might see |item| and assume that it's preceded by array1.each, rather than a times loop. It's wholly appropriate to call this variable i or idx, since those are pretty common names for a variable holding an index you're using to iterate through collections.

if array2[item] != array1[item]
return false
end
end
return true
end
end