I am working on the following problem: Write a function called same, which accepts two arrays. The function should return true if every value in the array has it's corresponding value squared in the second array. The frequency of the values must be the same.
The solution seems to be working except for the part where I compare the second array to the third array. Console log tells me they are the same but the comparison fails indicating they are not equal.
Why would second===third be false when they are the same?
function same(first, second) {
first.sort((a,b) => a-b)
console.log(first)
second.sort((a,b) => a-b)
console.log(second)
let third = first.map((a) => a**2)
console.log(third)
if (second === third) return true
else return false
}
$ node same.js
[ 1, 2, 3 ]
[ 1, 4, 9 ]
[ 1, 4, 9 ]
false