Tell us what’s happening:
So I solved it and then looked at the solutions. Was is okay for me to use isInterger? I didn’t even think to use the num % parseInt and i still don’t really understand what that one is doing either. I also looked at the reduce solution and didn’t really understand it either, but maybe that’s just because I struggle with the ternary stuff. Anyway I would appreciate it if I could get some feedback about maybe some things to keep in mind for future reference as well.
List item
Your code so far
const squareList = arr => {
// Only change code below this line
let positive = arr.filter(positive => (positive >= 0 && Number.isInteger(positive)));
console.log(positive);
let newArray = positive.map(element => (element*element));
return newArray;
// Only change code above this line
};
const squaredIntegers = squareList([4,5.6, 3.14, 42, 6, 8.34, -2]);
console.log(squaredIntegers);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
Challenge: Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
Link to the challenge: