From adbe7c23101410cfc907215b8fb0e73fff803bec Mon Sep 17 00:00:00 2001 From: Divya Date: Wed, 22 Aug 2018 20:51:58 -0700 Subject: [PATCH 1/2] I made array_equals.rb --- 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..d44d941 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 + final = false + if array1 == nil && array2 == nil + return true + end + if array1 == nil || array2 == nil + return false + end + + if array1.length == array2.length + final = true + x = 0 + while x < array1.length + if array1[x] != array2[x] + final = false + end + x += 1 + end + end + return final end From 97b889fbaae65ca616d924a29c1fd29a5855c21c Mon Sep 17 00:00:00 2001 From: Divya Date: Wed, 22 Aug 2018 21:28:06 -0700 Subject: [PATCH 2/2] I refactored array_equals.rb --- lib/array_equals.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index d44d941..978a9af 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,23 +1,25 @@ # 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) - final = false if array1 == nil && array2 == nil return true - end + end + if array1 == nil || array2 == nil return false end - if array1.length == array2.length - final = true - x = 0 - while x < array1.length - if array1[x] != array2[x] - final = false - end - x += 1 - end + if array1.length != array2.length + return false + end + + x = 0 + while x < array1.length + if array1[x] != array2[x] + return false + end + x += 1 end - return final + + return true end