DEV Community

Discussion on: Which Array Function When?

Collapse
 
yunoctry profile image
Yun

return (accumulator += (item === "Bob" ?1:0));

this way(using "?:" or "&&||" after equal sign) works better in lots of situation

Collapse
 
22samuelk profile image
Samuel

That = in += is redundant since the reducer only needs to return the new value, not change the old one. I mean, it'll still work, because the correct value is returned, but there's no need in changing the passed-in accumulator.