From dbdedd54e912b3e69dabaa637e877bb1b08c5d63 Mon Sep 17 00:00:00 2001 From: Shubha Rajan Date: Thu, 21 Feb 2019 20:36:29 -0800 Subject: [PATCH] working code with support for edge cases, including empty arrays and nil values --- lib/array_equals.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..253ada8 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,18 @@ # 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 + if !array1 && !array2 + return true + elsif !array1 || !array2 + return false + elsif array1.length == array2.length + i = 0 + while i < array1.length + return false if array1[i] != array2[i] + i += 1 + end + else + return false + end + return true end