Logo

Programming-Idioms

History of Idiom 202 > diff from v9 to v10

Edit summary for version 10 by steenslag:
[Ruby] Added comment about 2.7 version

Version 9

2019-10-05, 05:04:54

Version 10

2020-01-05, 23:13:28

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Code
s = data.sum{|i| i**2}
Code
s = data.sum{|i| i**2}
Comments bubble
Can be written as data.sum{ _1**2 } since Ruby 2.7