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

9 lines
186 B
Markdown

### Sum of array of numbers
Use `reduce()` to add each value to an accumulator, initialized with a value of `0`.
```js
var sum = arr =>
arr.reduce( (acc , val) => acc + val, 0);
```