I am currently working on a 6kyu challenge on codewars and I've encountered a frustrating issue that I can't seem to figure out. The task at hand involves comparing two arrays, a and b, to determine if they have the same elements with the same multiplicities. Specifically, in this case, "same" means that the elements in array b are the squares of the elements in array a.
Despite my efforts, my code keeps returning 1 consistently, even after making adjustments. I'm seeking an explanation as to why this is happening rather than just the answer to the problem. Any guidance would be greatly appreciated!
function checkTrue(element){
return element === true;
}
function compareArrays(array1, array2){
var squaredArray = array1.map(function(number){return number*number});
var outputArray = [];
for(var index = 0; index < squaredArray.length; index++){
if(array2.includes(squaredArray[index])){
return outputArray.push(true);
} else{
return outputArray.push(false);
}
}
return outputArray.every(checkTrue) ? true : false;
}
compareArrays([121, 144, 19, 161, 19, 144, 19, 11],[121, 14641, 20736, 361, 25921, 361, 20736, 361]);
// Resulting value: 1 (should be true)