After a reduce function: a [ ]

Tell us what’s happening:
How is it possible that sqrIntegers may be an array (according to the debugger is an empty array) since the function start to work over arr?

does it have to do with the [ ]declared as the second parameter of the reduce function? (whether I understood it?)

const squareList = arr => {
  return arr.reduce((sqrIntegers, num) => {
    return Number.isInteger(num) && num > 0
      ? sqrIntegers.concat(num * num)
      : sqrIntegers;
  }, []);
};

let arr = [2, 3];

console.log(squareList(arr));

Note: I solved the challenge. This is one of the posted solutions.

The second parameter of reduce allows you to set an initial value for the accumulator. In this case, the initial value is an array, so that the true case of the ternary expression has something in which to concat.

1 Like