Logo

Programming-Idioms

History of Idiom 54 > diff from v24 to v25

Edit summary for version 25 by Dodopod:
New JS implementation by user [Dodopod]

Version 24

2017-03-27, 19:20:36

Version 25

2017-05-30, 15:37:58

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Idiom #54 Compute sum of integers

Calculate the sum s of integer list x.

Code
var s = x.reduce((a, b) => a + b, 0);
Origin
https://stackoverflow.com/questions/1230233/how-to-find-the-sum-of-an-array-of-numbers
Demo URL
https://jsfiddle.net/Lpwwjbwk/