I came across this when reading this medium article: https://medium.com/@alexbeer/hi-nice-sum-up-of-different-duplicate-filters-eb4d3895fd14
aal89
2
Posts
A member registered May 08, 2019
Recent community posts
itch.io Community » Game Development » General Development · Replied to Panaxx in JavaScript's forEach is very slow!
itch.io Community » Game Development » General Development · Posted in JavaScript's forEach is very slow!
Kinda related, but something different.
You should reference the array you are looping through in the reduce method (or any other functional loop). Et voila, your loop is quicker. Don't even use the reference.
Examples:
// this one is quicker... sum = data.reduce((acc, curr, i, arr) => { return acc + curr * curr }) // than this one sum = data.reduce((acc, curr) => { return acc + curr * curr })
(am using Node 8)