Hacker News new | ask | show | jobs
by spiralx 1631 days ago
Surely the spread operator is nicer here?

    [1, 2, 3, 4, 5].reduce((acc, n) => n % 2 === 1 ? [ ...acc, 2 * n ] : acc, [])
1 comments

This is not efficient. Each iteration creates a new array instance due to the spread operator.
`acc.concat()` also creates a new array instance, so I don't get your point.