EDIT (see edit history for original that fails if there are duplicates in the first array):
Your original code works (at least for the example inputs). You are just doing more than necessary to get the output.
The input array included in your question...
[91, 15, 54, 53, 78, 80, 91]
...results in the following array after squaring the values:
[8281, 225, 2916, 2809, 6084, 6400, 8281]
All of these squared values are included in your comparison array (which also contains one additional value that is not generated by squaring the input array):
[8281, 225, 2916, 2809, 6084, 6400, 8282]
A slightly simpler approach would be to square the values in the first array and then use every and includes to check if every squared value exists in the second array. For example:
const squareCompare = (square, compare) => {
return square.map((x) => x ** 2).every((x) => compare.includes(x));
};
const t = squareCompare([91, 15, 54, 53, 78, 80, 91], [8281, 225, 2916, 2809, 6084, 6400, 8282]);
console.log(t);
// true
const f = squareCompare([2, 4, 2], [25, 4, 81]);
console.log(f);
// false
Run code snippetExpand snippet