From 37792873a2a6e98a2869812690f03794f5066f54 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 22 Aug 2018 22:11:12 -0700 Subject: [PATCH 1/2] completed everything except fix error for nil --- lib/array_equals.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..247ccdb 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,33 @@ # Determines if the two input arrays have the same count of elements # and the same integer values in the same exact order +require 'pry' def array_equals(array1, array2) - raise NotImplementedError + i = 0 + outputs = [] + if array1.to_s != array2.to_s + # ouput = true + # if array1.length != array2.length + return false + else + array1.each do |element| + if element == array2[i] + i += 1 + output = true + outputs << output + else + output = false + outputs << output + end + end + outputs.each do |output| + if output == false + return false + end + end + end + return true end + +array1 = [1, 2, 3] +array2 = [1, 2, 3] +p array_equals(array1, array2) From 00c76e18784e908c8e442457d3e5c6779a3cfc42 Mon Sep 17 00:00:00 2001 From: Amanda Ungco Date: Wed, 22 Aug 2018 22:27:09 -0700 Subject: [PATCH 2/2] figured out nil -- maybe, not sure if i was allowed to use that method --- lib/array_equals.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 247ccdb..d0ee6f8 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -9,7 +9,10 @@ def array_equals(array1, array2) # if array1.length != array2.length return false else - array1.each do |element| + if array1 == nil && array1 == array2 + return true + else + array1.each do |element| if element == array2[i] i += 1 output = true @@ -25,6 +28,7 @@ def array_equals(array1, array2) end end end +end return true end