Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem: questions about solution

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:

I’d quibble a little with some of those variable names and using let instead of const, but that looks like a great solution to me.

Thanks and yeah I don’t really think to use const ever cause I kind of forget when it’s appropriate. It does make sense since we don’t mutate these arrays .

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.