All pastes #804188 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-12-03 05:15 UTC
rendered paste body
class 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