Tell us what’s happening:
Alright, as far as I can tell, this code should be working. However, on this particular page, .filter()
and .map()
do not behave as I normally expect them to.
Input: [-3, 4.8, 5, 3, -3.2]
Output: [ -3, 4.8, 5, 3, -3.2 ]
Your code so far
const squareList = (arr) => {
// Only change code below this line
/*
To return an array of squared integers,
filter non-positive non-integers,
map those integers with a square.
*/
arr
.filter(num => num > 0 && Number.isInteger(num))
.map(int => Math.pow(int, 2));
return arr;
// Only change code above this line
};
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
.
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