Skip to content
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
24 changes: 21 additions & 3 deletions lib/array_equals.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# 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
i = 0
boolean_value = true

if array1 == nil && array2 == nil

Choose a reason for hiding this comment

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

this could be simiplified a bit with:

if array1.nil? && array2.nil?
  return true
elsif array1.nil? || array2.nil? # if one or the other is nil, but not both
  return false

boolean_value = true
elsif array1 == nil && array2 != nil
boolean_value = false
elsif array1 != nil && array2 == nil
boolean_value = false
elsif array1.length == array2.length
array1.each do |integer|
if integer != array2[i]
boolean_value = false
end
i += 1
end
else boolean_value = false
end
return boolean_value
end

1 change: 1 addition & 0 deletions test/array_equals_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'minitest/autorun'
require 'minitest/reporters'
require_relative '../lib/array_equals'
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

describe "array equals" do
describe "basic tests" do
Expand Down