Programming-Idioms

History of Idiom 54 > diff from v23 to v24

Edit summary for version 24 :
[Ruby] 2 ways => new impl 1957

Version 23

2017-03-27, 19:20:06

Version 24

2017-03-27, 19:20:36

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
s = x.sum
Code
s = x.sum
Comments bubble
Works since Ruby 2.4. Older versions:
s = x.reduce(:+)
Comments bubble
Works since Ruby 2.4
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-reduce