comp(a, b) returns true because in b 121 is the square of 11, 14641 is the square of 121, 20736 the square of 144, 361 the square of 19, 25921 the square of 161, and so on. It gets obvious if we write b's elements in terms of squares:
a = [121, 144, 19, 161, 19, 144, 19, 11]
b = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]
function comp(array1, array2){
if (!array1 || !array2) { return false };
let sortedArray1 = array1.sort(function(a,b) { return a-b });
let sortedArray2 = array2.sort(function(a,b) { return a-b });
let calculatedArray1 = sortedArray1.map(a => a*a)
for(let i = 0; i < calculatedArray1.length; i++) {
if (calculatedArray1[i] !== sortedArray2[i]) {
return false;
}
}
return true;
}