From 8d86a3dd62ea8c51bf9505b719e9d04eae9b4251 Mon Sep 17 00:00:00 2001 From: carlabosco Date: Thu, 28 Feb 2019 12:38:08 -0800 Subject: [PATCH 1/3] Create array_equals.rb --- array_equals.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 array_equals.rb diff --git a/array_equals.rb b/array_equals.rb new file mode 100644 index 0000000..8ec1ba8 --- /dev/null +++ b/array_equals.rb @@ -0,0 +1,25 @@ +# Author a method named array_equals that accepts two integer +# arrays as input parameters. The method should return true if +# the arrays contain the same count of elements, the element +# values in the array are the same and they are in the same +# exact order. Otherwise, the method should return false. + +def array_equals?(arr1, arr2) + if arr1.length == arr2.length + loop_count = arr1.length + loop_count.times do |i| + if arr1[i] != arr2[i] + return false + else + i += 1 + if i == loop_count + return true + end + end + end + else + return false + end +end + +array_equals?([1, 2, 3], [1, 2, 3]) From 7a05757f65844af28ed3c0da6db60d632122f6a6 Mon Sep 17 00:00:00 2001 From: Carla Bosco Date: Tue, 5 Mar 2019 21:06:45 -0800 Subject: [PATCH 2/3] Moved file to lib folder --- 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..cae89e6 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 + if (array1 == nil && array2 == nil) || (array1 == [] && array2 == []) + return true + elsif array1 == nil || array2 == nil + return false + end + + if array1.length == array2.length + loop_count = array1.length + loop_count.times do |i| + if array1[i] != array2[i] + return false + else + i += 1 + if i == loop_count + return true + end + end + end + else + return false + end + end From 0d315860132c2d2c59abace9ed443f3f372c8fe1 Mon Sep 17 00:00:00 2001 From: Carla Bosco Date: Tue, 5 Mar 2019 21:11:38 -0800 Subject: [PATCH 3/3] "Solving merge" --- array_equals.rb | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 array_equals.rb diff --git a/array_equals.rb b/array_equals.rb deleted file mode 100644 index 8ec1ba8..0000000 --- a/array_equals.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Author a method named array_equals that accepts two integer -# arrays as input parameters. The method should return true if -# the arrays contain the same count of elements, the element -# values in the array are the same and they are in the same -# exact order. Otherwise, the method should return false. - -def array_equals?(arr1, arr2) - if arr1.length == arr2.length - loop_count = arr1.length - loop_count.times do |i| - if arr1[i] != arr2[i] - return false - else - i += 1 - if i == loop_count - return true - end - end - end - else - return false - end -end - -array_equals?([1, 2, 3], [1, 2, 3])