From b7aaed772d62173ea2cf6e894b326b35c1d11a99 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Fri, 24 Aug 2018 22:36:43 -0700 Subject: [PATCH] array-equals --- .DS_Store | Bin 0 -> 6148 bytes lib/array_equals.rb | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8a0007a9b623dc96a3d93cc722634cf6e67e2f9b GIT binary patch literal 6148 zcmeHKQA-;^5S}%$Zc?OqDCpz86nqGhAS8uSxW@S4LqU4QKB(xOck0peHsme_o2J}L ze?x=b0??jEg+|Nf@&mZnkZ_Ce50=7RZm0a6?upLL^{l@EcmF9k& zMnjz(hY^PCeu>jijeBa8hMBJ8nE@$lvbNt?o=iGxZ<|iL)txq-Nw?E&I-O2?I<3j2 zH|_VE2dC%XCf}z&ewkGect~k^#rO{{(BSEvdBZeO=`ngJTEY-~_zDpmAw>y9Ws<}a z#@r;S2A^O9K0qHnBCf(IgfkgGXENp?g8|k*gsdD1m-k0L*G0HN#>_$>7gipa0p1Ss zz{u_ha8A5V_^_ID8i&7npDA0 z48d;)VbXEj<@my&Ne7|7jCJ_Sf?p_tpB}=|;UHXtwzUjc2FeUnOt(Sz|Hl3A|8kP; zSq3Zv&x!$2?R)(mPKocj OkASAZHkN@$W#BKRK*5** literal 0 HcmV?d00001 diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..06b6057 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,32 @@ # 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 + if array1.nil? && array2.nil? + return true + elsif array1.nil? && !array2.nil? || !array1.nil? && array2.nil? + return false + elsif array1 == [] && array2 == [] + return true + elsif array1 == [] && array2 != [] || array1 != [] && array2 == [] + return false + end + + + idx = 0 + + if array1.length != array2.length + return false + end + + while idx <= array1.length + if array1[idx] != array2[idx] + return false + else + idx += 1 + end + end + + return true + end