Skip to content
Open
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
34 changes: 33 additions & 1 deletion lib/array_equals.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# 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
#raise NotImplementedError
#Check for the nil class first because array methods will not work

Choose a reason for hiding this comment

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

Danielle,
Thank you for going over this with me. I really enjoyed how detailed your codes are and how you parsed out the reasoning for each parts of the problem to solve the problem.

if array1 == nil || array2 == nil
if array1 == nil && array2 == nil
return true
else
return false
end
end

#Check for empty arrays
if array1[0]==nil && array2[0]==nil
return true
elsif (array1[0] == nil) || (array2[0] == nil)
return false
end

#Now we know that at least both arrays have elements we can determine their length
#and look at each element to see if each index is the same.
len1 = array1.length
len2 = array2.length

if len2 != len1
return false
end


len1.times do |index|
if array1[index] != array2[index]
return false
end
end
return true
end