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.