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.9.2 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.9.1 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.9.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.8.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.7.1 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.7.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.6 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.5 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.4 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.3 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.2 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.1 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.6.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.5.3 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.5.2 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.5.1 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.5.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.4.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.3.0 lib/madvertise/ext/enumerable.rb
madvertise-ext-0.2.2 lib/madvertise/ext/enumerable.rb