Y
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
v413
1631 days ago
This is not efficient. Each iteration creates a new array instance due to the spread operator.
link
spiralx
1625 days ago
`acc.concat()` also creates a new array instance, so I don't get your point.
link