From 9603febe5413e712e003cd926949820f6b89216a Mon Sep 17 00:00:00 2001 From: Chris M Date: Sun, 18 Aug 2019 21:36:00 -0700 Subject: [PATCH 1/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 232392b..a5707a8 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,5 @@ Determines if the two input integer arrays are equal. The two arrays will be con * 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. + +**Due Date** This assignment is due **Monday August 26th** From 4c9e2c3fec693b6d2fd12df7deb2354647a6e315 Mon Sep 17 00:00:00 2001 From: Chris M Date: Thu, 22 Aug 2019 11:49:42 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5707a8..a283718 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ Determines if the two input integer arrays are equal. The two arrays will be con **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. -**Due Date** This assignment is due **Monday August 26th** +**Due Date** This assignment is due **Monday Sept 2nd** From 5e74049a599ef1cd4d1c25104d875c4a21f4cf63 Mon Sep 17 00:00:00 2001 From: Kristina Date: Sun, 25 Aug 2019 11:23:39 -0700 Subject: [PATCH 3/3] Completed and passed all tests. --- lib/array_equals.rb | 19 +++++++++++++++++-- test/array_equals_test.rb | 34 +++++++++++++++++----------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/array_equals.rb b/lib/array_equals.rb index 58e8369..6eed0c2 100644 --- a/lib/array_equals.rb +++ b/lib/array_equals.rb @@ -1,5 +1,20 @@ # 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 -end + if array1 == nil && array2 == nil + return true + elsif array1 == nil || array2 == nil + return false + else + if array1.length == array2.length #if neither are nil, check their length + array1.zip(array2).each do |x, y| #if the length is the same, iterate thru both arrays + if x != y + return false + end + end + return true + else + return false + end + end +end diff --git a/test/array_equals_test.rb b/test/array_equals_test.rb index f745cf7..575e60d 100644 --- a/test/array_equals_test.rb +++ b/test/array_equals_test.rb @@ -7,65 +7,65 @@ it "arrays are equal" do array1 = [10, 20, 30, 40, 50, 60] array2 = [10, 20, 30, 40, 50, 60] - + array_equals(array1, array2).must_equal true end - + it "arrays not equal: first six elements are same" do array1 = [10, 20, 30, 40, 50, 60] array2 = [10, 20, 30, 40, 50, 60, 70] - + array_equals(array1, array2).must_equal false end - + it "arrays not equal: same count of elements" do array1 = [10, 20, 30, 40, 50, 60] array2 = [20, 3, 50, 10, 68, 74] - + array_equals(array1, array2).must_equal false end end - + describe "edge cases" do it "arrays are empty: equal" do array1 = [] array2 = [] - + array_equals(array1, array2).must_equal true end - + it "only first array is empty: not equal" do array1 = [] array2 = [50, 30] - + array_equals(array1, array2).must_equal false end - + it "only second array is empty: not equal" do array1 = [20] array2 = [] - + array_equals(array1, array2).must_equal false end - + it "arrays are nil: equal" do array1 = nil array2 = nil - + array_equals(array1, array2).must_equal true end - + it "only first array is nil: not equal" do array1 = nil array2 = [10, 20] - + array_equals(array1, array2).must_equal false end - + it "only second array is nil: not equal" do array1 = [20] array2 = nil - + array_equals(array1, array2).must_equal false end end