Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
(2 edits) (+3)

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.


// 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)


Interesting find!

I wonder how this came to be, looking forward for a more in-depth post or article about this.


I came across this when reading this medium article:

Just tried it. You're right! Very strange