From 727d665e6a75543ab5cfe122342f53c5c556abf3 Mon Sep 17 00:00:00 2001 From: laneia Date: Wed, 27 Feb 2019 15:54:29 -0800 Subject: [PATCH] passing all tests --- lib/array_equals.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..bb33a35 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,26 @@ # 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 + i = 0 + + if (array1 == nil && array2 == nil) || (array1 == [] && array2 == []) + return true + elsif array1 == nil || array2 == nil + return false + end + + if array1.length == array2.length + until i > array1.length + if array1[i] != array2[i] + return false + end + i += 1 + end + return true + end + return false end + +array3 = [10, 20, 30, 40, 50, 60] +array4 = [10, 20, 30, 40, 50, 60, 70] +p array_equals(array3, array4)