All pastes #804190 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-12-03 05:18 UTC
rendered paste body
class Array
  def sum(&block)
    inject(&(block_given? ? block : lambda{|s,v| s + v}))
  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