I'm tasked with writing a function that takes two 1-dimensional arrays of simple values (no objects, etc), and returns true only if they are equal. The function also must use the Array.forEach()
method.
So far, I've tried
function eql(arr1, arr2) {
if(arr1.length !== arr2.length){return false}
arr1.forEach((element, index) => {
if(element !== arr2[index]){
return false
}
})
return true
}
And this gets most of my tests to pass, although the cases that are still failing are
eql([1], [2])
eql(['a', 'b'], ['a', 'c'])
eql([1], ['1'])
All three of these cases are returning true
, when I'm expecting false
. Thanks in advance for any help, I've been trying to sort through the logic on my own and feel like I've hit a wall!