Logo

Programming-Idioms

History of Idiom 54 > diff from v9 to v10

Edit summary for version 10 by :

Version 9

2015-08-23, 10:53:27

Version 10

2015-09-03, 16:00:00

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.reduce(:+)
s = x.reduce(0) { |memo, elem| memo + elem }
Doc URL
http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-reduce