Tell us what’s happening:
Inside filter method if we put Math.pow(currNum,2)
, why it return [5,3]
and not [25,9]
Your code so far
const squareList = (arr) => {
// only change code below this line
let sqrtArray = arr.filter(currNum =>
(currNum %1 ===0 && currNum >0)
).map(currNum=>Math.pow(currNum,2));
return sqrtArray;
// only change code above this line
};
// test your code
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
.
Challenge: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem