From 5ae3739e58a40f1bf3ad52658f845fa241bc370e Mon Sep 17 00:00:00 2001 From: Hana Date: Fri, 1 Mar 2019 08:43:29 -0800 Subject: [PATCH] finished project, not optional --- array-equals.rb | 32 ++++++++++++++++++++++++++++++++ lib/array_equals.rb | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 array-equals.rb diff --git a/array-equals.rb b/array-equals.rb new file mode 100644 index 0000000..e1bf348 --- /dev/null +++ b/array-equals.rb @@ -0,0 +1,32 @@ +# CS Fun +# Array Equals + +def array_equals(int_array1, int_array2) + # if both are empty + if (int_array1 == nil) && (int_array2 == nil) + return true + + # if one is empty, one is not + elsif (int_array1 == nil) && (int_array2 != nil) + return false + elsif (int_array1 != nil) && (int_array2 = nil) + return false + + # if they not the same length + elsif int_array1.length != int_array2.length + return false + + # if they are the same length + else + index = 0 + + int_array1.length.times do + if int_array1[index] != int_array2[index] + return false + end + end + + # if it passes all checks + return true + end +end diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..c8f9a22 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,38 @@ # 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 + # unless + # raise NotImplementedError, + # end + + # if both are empty + if (array1 == nil) && (array2 == nil) + return true + + # if one is empty, one is not + elsif (array1 == nil) && (array2 != nil) + return false + elsif (array1 != nil) && (array2 = nil) + return false + + # if they not the same length + elsif array1.length != array2.length + return false + else + return true + end + + # # if they are the same length + # else + # index = 0 + + # array1.length.times do + # if array1[index] != array2[index] + # return false + # end + # end + + # # if it passes all checks + # return true + # end end