I have squared all elements of the first array, and I have squared all elements of the second array. Then, I added up the sum in each array. I then am stating "if sumOfResultOne is greater than sumOfResultTwo, then return ‘true’. Else if the sumOfResultTwo is greater than sumOfResult One, then return ‘false’. I don’t see why this code is not working ):

function arrayMadness(a, b) {
let resultOne = a.map(x => x ** 2);
console.log(resultOne);
let resultTwo = b.map(x => x ** 2);
console.log(resultTwo);
const sumOfResultOne = resultOne.reduce((acc, cur) => acc + cur, 0);
const sumOfResultTwo = resultTwo.reduce((acc, cur) => acc + cur, 0);
if (sumOfResultOne > sumOfResultTwo) {
return true;
} else if (sumOfResultTwo > sumOfResultOne) {
return false;
}
}

I’m trying to get to the point where I can solve the problems. Then, after I am able to pretty much solve any problem, “tweak” the code to make it like the way you said. This is just the only way I could think of.

That is a perfectly fine approach. I’m just saying that the math performed in the map() fits quite well inside the reduce().

I know reduce() is usually taught to beginners using addition (which is fine) but just make sure that doesn’t limit you to all the options it really gives you. It is a powerful method and only using it for addition would be a shame.

In this case, what I’m suggesting isn’t really much different than using it for addition, just with some extra math tacked on to the addition.

I wish I were able to think more on my feet with the built-in JavaScript functions like reduce(). It’s just very abstract and I’ve only learned to do it for addition, subtraction, etc etc lol. but I had it wrong because I was doing ** 2 and not ** 3 for a cube lol