MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuyind/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
2
const sum = arr.reduce((accumulator, currentVal) => accumulator += currentVal);
Super useful whenever you need to sum all the array’s elements.
6 u/Michie1 Mar 19 '19 Math.sum(...arr) 3 u/NoInkling Mar 19 '19 Not a thing in JS. → More replies (1)
6
Math.sum(...arr)
3 u/NoInkling Mar 19 '19 Not a thing in JS. → More replies (1)
3
Not a thing in JS.
→ More replies (1)
2
u/ompelpel Mar 19 '19
const sum = arr.reduce((accumulator, currentVal) => accumulator += currentVal);
Super useful whenever you need to sum all the array’s elements.