Logo

Programming-Idioms

History of Idiom 203 > diff from v3 to v4

Edit summary for version 4 by gplf:
New Ruby implementation by user [gplf]

Version 3

2019-09-29, 11:52:41

Version 4

2019-10-02, 01:16:27

Idiom #203 Calculate mean and standarddeviation

Calaculate m, the mean and s, the standard deviation of data, an array of floating point values.

Idiom #203 Calculate mean and standarddeviation

Calaculate m, the mean and s, the standard deviation of data, an array of floating point values.

Code
m  = data.sum / data.length.to_f
sd = Math.sqrt data.sum { |n| (m-n)**2 } / data.length.to_f 
Comments bubble
.to_f forces floating point