Flatten array with JavaScript reduce function

2 comments · 40% upvoted · source · other discussions

comments

helloiamsomeone

For the millionth time, stop generating a million intermediate array copies for a simple flatten operation.

This is part of the language now [1][2], but even for polyfill you should be using a stack based flatten.