Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(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.

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)

(+1)

Interesting find!

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

(+1)

I came across this when reading this medium article: https://medium.com/@alexbeer/hi-nice-sum-up-of-different-duplicate-filters-eb4d3895fd14

Just tried it. You're right! Very strange