Sha256: 9f19dfe506d7ecbb7a5edc3f16829c7d9a59c22769408f91aade34c06c577eb8

Contents?: true

Size: 306 Bytes

Versions: 25

Compression:

Stored size: 306 Bytes

Contents

module Enumerable
  def sum
    reduce(:+)
  end

  def mean
    sum.to_f / length
  end

  def variance
    m = mean
    reduce(0) {|accum, item| accum + (item - m) ** 2}.to_f / (length - 1)
  end

  def stdev
    Math.sqrt(variance)
  end

  def percentile(pc)
    sort[(pc * length).ceil - 1]
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
madvertise-ext-0.2.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.1.3 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.1.2 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.1.1 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.1.0 lib/madvertise/ext/enumerable.rb