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.
what is use of square bracket after short hand if-else in 5th line of code.
If this is omitted it gives mesaage conact is not a function

Your code so far

const squareList = arr => {
  // Only change code below this line
  
  return arr.reduce((sum,no)=>{
    return Number.isInteger(no) && no>0
  ?sum.concat(no*no):sum},[]);
  // 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

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

Link to the challenge:

That is the initial value for the reduce

initialValue

A value to which previousValue is initialized the first time the callback is called. If initialValue is specified, that also causes currentValue to be initialized to the first value in the array. If initialValue is not specified, previousValue is initialized to the first value in the array, and currentValue is initialized to the second value in the array.

For more context refer to

1 Like

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