Unnamed
public text v1 · immutableclass Array
def sum
if block_given?
inject{|sum, v| yield(sum, v) }
else
inject{|sum, v| sum + v }
end
end
def mean(&block)
sum(&block).to_f / size
end
def deviation
# sqrt( e(x^2) - (e(x))^2 )
Math.sqrt( mean{|sum, x| sum + x ** 2 } - mean ** 2 )
end
end