From b5c4198fb21886a6cfa33fdd0133e4de2326cafc Mon Sep 17 00:00:00 2001 From: Amal Hassan-Ali Date: Sat, 31 Aug 2019 17:34:13 -0700 Subject: [PATCH 1/2] added array-equals method --- lib/array_equals.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..1a130d4 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -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 + +require 'pry' def array_equals(array1, array2) - raise NotImplementedError + + + if array1 == nil && array2 == nil + return true + elsif array1 == nil && array2 != nil + return false + elsif array2 == nil && array1 != nil + return false + end + + + if array1.length > array2.length + big_arr = array1 + small_arr = array2 + + else + big_arr = array2 + small_arr = array1 + + end + + big_arr.each_with_index do |num, index| + if num != small_arr[index] + return false + end + + + end + return true + + end From 0364f9f6f34bb4349eddab081cf2fb2ec81dc8ef Mon Sep 17 00:00:00 2001 From: Amal Hassan-Ali Date: Sat, 31 Aug 2019 17:46:30 -0700 Subject: [PATCH 2/2] removed variable --- lib/array_equals.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 1a130d4..ccaf50a 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,7 +1,6 @@ # 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) @@ -14,18 +13,13 @@ def array_equals(array1, array2) end - if array1.length > array2.length - big_arr = array1 - small_arr = array2 - - else - big_arr = array2 - small_arr = array1 - + if array1.length != array2.length + return false end - - big_arr.each_with_index do |num, index| - if num != small_arr[index] + + + array1.each_with_index do |num, index| + if num != array2[index] return false end