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

Tell us what’s happening:
Describe your issue in detail here.

Hi all, can someone point out what’s wrong with my code?
my logic is: filter arr into positives real numbers => convert the real numbers into integers => calculate squares of those intergers.

Cheers

Your code so far

const squareList = arr => {
  // Only change code below this line
  let positive = arr.filter(intergers => intergers > 0);
  let temp = positive.map(floats => parseInt(floats));
  let square = temp.map(numbers => numbers * numbers);
  return square;
  
  // 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_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15

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

Link to the challenge:

you don not need to convert it, instruction says

The function should return a new array containing the squares of only the positive integers (decimal numbers are not integers)

So according to this instruction, I would rather get rid of both negative numbers and positive floats. So I would have an array of ONLY positive integers

Right, now I get it. I think I just misinterpreted the instructions. Thanks

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