From 5bbc8d20cd78b0bbb35a5cc97a2002966e7b5a68 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Wed, 27 Feb 2019 21:22:48 -0800 Subject: [PATCH 1/2] compares two arrays --- lib/array_equals.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..aa2b9f8 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -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 + if array1 == nil && array2 == nil + return true + elsif array1 == [] && array2 == [] + return true + elsif array1 == nil || array2 == nil + return false + elsif array1.length != array2.length + return false + elsif array1.length == array2.length + array1.length.times do |compare_1, compare_2| + x = 0 + if array1[x] == array2[x] + x += 1 + return true + else + return false + end + end + end end From 8b7c6281dc71e304a81a0a7bf3e786f6a8e81645 Mon Sep 17 00:00:00 2001 From: Heather Izumi Date: Mon, 4 Mar 2019 20:15:03 -0800 Subject: [PATCH 2/2] Fixed array_equals conditionals --- lib/array_equals.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index aa2b9f8..ae53ad2 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -3,21 +3,22 @@ def array_equals(array1, array2) if array1 == nil && array2 == nil return true - elsif array1 == [] && array2 == [] - return true elsif array1 == nil || array2 == nil return false elsif array1.length != array2.length return false elsif array1.length == array2.length - array1.length.times do |compare_1, compare_2| - x = 0 + element_count = 0 + array1.length.times do |x| if array1[x] == array2[x] - x += 1 - return true + element_count += 1 else return false end end end + + if array1.length == element_count + return true + end end