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

Tell us what’s happening:
Having troubles returning the accumulator. Is there a reson, why it won’t be returned?
Your code so far

const squareList = (arr) => {
  // Only change code below this line
  arr.reduce((res, elem) => {
    if(elem >=0 && Number.isInteger(elem)){
      res.push(elem*elem)
    }
  }, [])
      return res;
  // Only change code above this line
};

const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
console.log(squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69

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

Link to the challenge:

I would format your code and check where the return statement lies in the scopes

My bad I also put the return statement in the reduce callback function before:

const squareList = (arr) => {
  // Only change code below this line
  arr.reduce((res, elem) => {
    if(elem >=0 && Number.isInteger(elem)){
      res.push(elem*elem)
    }
    return res;
  }, [])
  // Only change code above this line
};

Yet it returns undefined :frowning:

Better but now the outer function needs a return statement

Thank you I had to return the whole function :+1:

1 Like

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