MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiv61eb/?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. -1 u/Michie1 Mar 19 '19 Wow, you are right. Math.sum is not a function. I'm confusing it with Math.min/max and was extrapolating it would exist for sum.The following package should work:import * as math from 'mathjs'; math.sum(arr);
6
Math.sum(...arr)
3 u/NoInkling Mar 19 '19 Not a thing in JS. -1 u/Michie1 Mar 19 '19 Wow, you are right. Math.sum is not a function. I'm confusing it with Math.min/max and was extrapolating it would exist for sum.The following package should work:import * as math from 'mathjs'; math.sum(arr);
3
Not a thing in JS.
-1 u/Michie1 Mar 19 '19 Wow, you are right. Math.sum is not a function. I'm confusing it with Math.min/max and was extrapolating it would exist for sum.The following package should work:import * as math from 'mathjs'; math.sum(arr);
-1
Wow, you are right. Math.sum is not a function. I'm confusing it with Math.min/max and was extrapolating it would exist for sum.
Math.sum is not a function
The following package should work:
import * as math from 'mathjs'; math.sum(arr);
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.