Continuing the discussion from freeCodeCamp Challenge Guide: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem:
I solved the given problem using the .filter()
from the first solution, but instead of using Math.pow
, I used just simple multiplication since not all Math
methods have been shown or used.
myCode:
const squareList = arr => {
// Only change code below this line
return arr.filter(num => num > 0 && num % parseInt(num) === 0)
.map(num => num * num);
// Only change code above this line
};
const squaredIntegers = squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]);
console.log(squaredIntegers);
.filter()
numbers that are not greater than zero &&
numbers that not do equal zero when finding the remainder
bewtween a num
and a num
that has been passed through parseInt()
.
`.map()` through the array and take a `num` in its place and times it by itself.