From b9dade8079a2f0a84fb969f04c05f5586b3b41fa Mon Sep 17 00:00:00 2001 From: Jansen Date: Wed, 27 Feb 2019 17:11:26 -0800 Subject: [PATCH 1/2] Create array_equals method --- lib/array_equals.rb | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..0c9303d 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,45 @@ # 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 + return true + end + + if (array1 == nil && array2 != nil) || (array1 != nil && array2 == nil) + return false + end + + if array1.length != array2.length + return false + end + + (array1.length).times do |i| + if array1[i] != array2[i] + return false + end + end + return true end + +# def array_equals(array1, array2) +# if array1.length != array2.length +# return false +# else +# array1.each_with_index do |element, i| +# if element != array2[i] +# return false +# end +# end +# end + +# return true +# end + +# 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. +# Note: Do not use Array class methods for comparing the whole array at once. +# You may use array indexing to retrieve one element at a time, +# you may compare individual elements with each other and you may retrieve the length of an array. +# Do not use any other Ruby provided functions. From 84b84b4772349e1343187322d978905cfe516bbd Mon Sep 17 00:00:00 2001 From: Jansen Date: Wed, 27 Feb 2019 17:15:32 -0800 Subject: [PATCH 2/2] Clean up comments --- lib/array_equals.rb | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 0c9303d..d2aec30 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,3 @@ -# 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) if array1 == nil && array2 == nil return true @@ -20,26 +18,3 @@ def array_equals(array1, array2) end return true end - -# def array_equals(array1, array2) -# if array1.length != array2.length -# return false -# else -# array1.each_with_index do |element, i| -# if element != array2[i] -# return false -# end -# end -# end - -# return true -# end - -# 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. -# Note: Do not use Array class methods for comparing the whole array at once. -# You may use array indexing to retrieve one element at a time, -# you may compare individual elements with each other and you may retrieve the length of an array. -# Do not use any other Ruby provided functions.