From 7a936a2e2bd9537240dce6c92bc0fc912377f237 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 23 Aug 2018 07:26:40 -0700 Subject: [PATCH 1/2] Finished the array equals method --- lib/array_equals.rb | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..6627216 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,41 @@ # 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 + #raise NotImplementedError +#Check for the nil class first because array methods will not work + if array1 == nil || array2 == nil + if array1 == nil && array2 == nil + return true + else + return false + end + end + +#Check for empty arrays + if array1[0]==nil && array2[0]==nil + return true + elsif (array1[0] == nil) || (array2[0] == nil) + return false + end + +#Now we know that at least both arrays have elements we can determine their length +#and look at each element to see if each index is the same. + len1 = array1.length + len2 = array2.length + + if len2 != len1 + return false + end + + + len1.times do |index| + if array1[index] != array2[index] + return false + end + end + return true end + +array1 = nil +array2 = [10,20] +puts array_equals(array1, array2) From b8758902622a7e5512b26d341b3dd162fd514790 Mon Sep 17 00:00:00 2001 From: Danielle Metzner Date: Thu, 23 Aug 2018 07:28:34 -0700 Subject: [PATCH 2/2] Removed testing output at the end or array_equals.rb --- lib/array_equals.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 6627216..522e056 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -19,7 +19,7 @@ def array_equals(array1, array2) end #Now we know that at least both arrays have elements we can determine their length -#and look at each element to see if each index is the same. +#and look at each element to see if each index is the same. len1 = array1.length len2 = array2.length @@ -35,7 +35,3 @@ def array_equals(array1, array2) end return true end - -array1 = nil -array2 = [10,20] -puts array_equals(array1, array2)