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
24 changes: 24 additions & 0 deletions lib/array_equals.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# 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)
true_false_array = []

Choose a reason for hiding this comment

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

It seems a little wasteful to build an entire array here. Not so efficient. It does work however.


if array1 == nil || array2 == nil
if array1 == nil && array2 == nil
true_false_array << "true"
else
true_false_array << "false"
end
else
if array1.length == array2.length
array1.length.times do |index|
if array1[index] == array2[index]
true_false_array << "true"
else
true_false_array << "false"
end
end
else
true_false_array << "false"
end
end

return true_false_array.delete("false") == nil
raise NotImplementedError
end