There's multiple issues:
somethingIsTrue ? doSomething();
is not valid in JavaScript. See MDN on ternary operator- Frankly, I don't think
Array.prototype.reduce
is the right choice. Reduce creates something from all array members. I mean you could use it for this, but the code would be unnecesarily obscure. For generic looping, use eithermap
(1:1 conversion of array elements) orforEach
I'd use forEach
, or just classic for
: