Files
30-seconds-of-code/snippets/sum-of-array-of-numbers.md
Angelos Chalaris bb40a7ec08 Additional snippets
2017-11-30 19:12:13 +02:00

186 B

Sum of array of numbers

Use reduce() to add each value to an accumulator, initialized with a value of 0.

var sum = arr =>
  arr.reduce( (acc , val) => acc + val, 0);