Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem question about the parseInt

How does %parseInt(number) ===0
return only numbers without a decimal? Doesn’t parseInt(number) convert the decimal to a whole number? I can’t seem to wrap my head how its returning the numbers that are not decimals. I would really appreciate any advice back. Thank you for taking the time to help!

  **Your code so far**
const squareList = arr => {
// Only change code below this line
return arr
.filter(number => number > 0 && number % parseInt(number) ===0)
};

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/102.0.5005.115 Safari/537.36

Challenge: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem

Link to the challenge:

The a%b operator returns the remainder. If the remainder is 0, then a/b divides evenly.

That’s a hip way to do it but I would suggest this wonderfully clear builtin – Number.isInteger()

1 Like

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