Cannot understand how the ternary op works here

So I solve this challenge:

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem

using a combination of .filter and .map, but I can’t really figure out how the second solution works, can anyone help me translate it into plain English?

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

from the third line: if num is an integer bigger than zero, concat num * num it to sqrIntegers; if not… :thinking: :thinking: :thinking: what?

…then just return the current value of sqrIntegers, ignoring the current value (ie do nothing and go on to the next value). The callback function for reduce has to return the accumulator, as that value is what gets passed in the next time the function is called

1 Like

Ahhh, I see now. Interesting way to solve this. Thank you