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

Sockets - Hana #47

Open
wants to merge 1 commit 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
32 changes: 32 additions & 0 deletions array-equals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CS Fun
# Array Equals

def array_equals(int_array1, int_array2)

Choose a reason for hiding this comment

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

Nice choice in naming them int_array. This clearly expresses what is being tested.

# if both are empty
if (int_array1 == nil) && (int_array2 == nil)
return true

# if one is empty, one is not
elsif (int_array1 == nil) && (int_array2 != nil)
return false
elsif (int_array1 != nil) && (int_array2 = nil)
return false

# if they not the same length
elsif int_array1.length != int_array2.length
return false

# if they are the same length
else
index = 0

int_array1.length.times do
if int_array1[index] != int_array2[index]
return false
end
end

# if it passes all checks

Choose a reason for hiding this comment

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

Excellent work! Very clear code. One case to consider (but it's totally optional) is guarding against incorrect input within the arrays. What would happen if you passed in int_array1 = ["1"] for example?

return true
end
end
35 changes: 34 additions & 1 deletion lib/array_equals.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# 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
# unless
# raise NotImplementedError,
# end

# if both are empty
if (array1 == nil) && (array2 == nil)
return true

# if one is empty, one is not
elsif (array1 == nil) && (array2 != nil)
return false
elsif (array1 != nil) && (array2 = nil)
return false

# if they not the same length
elsif array1.length != array2.length
return false
else
return true
end

# # if they are the same length
# else
# index = 0

# array1.length.times do
# if array1[index] != array2[index]
# return false
# end
# end

# # if it passes all checks
# return true
# end
end