All pastes #804182 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-12-03 05:11 UTC
rendered paste body
class Array
  def sum
    inject( nil ) { |sum, x| block_given? ? yield(sum, x) : sum + x }
  end
  def mean
    sum.to_f / size
  end
  def deviation
    # sqrt( e(x^2) - (e(x))^2 )
    Math.sqrt( mean{|sum, x| sum + x ** 2 }/size - mean ** 2 )
  end
end