From 51e4824539db1c1ab9076658f3d2b302aaf6437a Mon Sep 17 00:00:00 2001 From: Kate Date: Thu, 28 Feb 2019 22:07:00 -0800 Subject: [PATCH 1/2] turning in --- lib/array_equals.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..5a965cd 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -2,4 +2,51 @@ # 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 + index = 0 + while index < array_length + if array1[current_index] != array2[current_index] + return false + end + index += 1 + return true + else + return false + end + end + end end + + +# NOTES WHILE WORKING THROUGH + +# if +# array1.length =! array2.length +# returns false +# break + +# index = 0 +# while index < array.length +# element = array[index] +# #do operation +# index += 1 +# end + +# array_equals + +# false? +# arrays are not exactly the same +# element values different +# elements not in the same order + +# true? +# arrays have some # of elements +# element values are the same +# order is the same From ea6902bd25eb71228a106b7c068a2bdc9f6a1d7c Mon Sep 17 00:00:00 2001 From: Kate Nichols <43222927+KateAnnNichols@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:48:04 -0800 Subject: [PATCH 2/2] Update array_equals.rb --- lib/array_equals.rb | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 5a965cd..37905c6 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -2,29 +2,20 @@ # 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 - index = 0 - while index < array_length - if array1[current_index] != array2[current_index] - return false - end - index += 1 - return true - else - return false + if array1 == [] && array2 == [] || array1 == nil && array2 == nil + return true + elsif array1 == nil || array2 == nil || array1.length != array2.length + return false + else + array1.length.times do |i| + if array2[i] != array1[i] + return false + end end + return true end - end end - # NOTES WHILE WORKING THROUGH # if