Sha256: 8a73dd667128b69d085bbf0b13d9f087a662c04515df573edffc25ddaac859e9

Contents?: true

Size: 502 Bytes

Versions: 1

Compression:

Stored size: 502 Bytes

Contents

module Enumerable
  def each_recursive(&block)
    self.each do |n|
      block.call(n)
      n.each_recursive(&block) if Enumerable === n
    end
  end

  def sum
    return self.inject(0){|accum, i| accum + i }
  end

  def mean
    return self.sum / self.length.to_f
  end

  def sample_variance
    m = self.mean
    sum = self.inject(0){|accum, i| accum + (i - m) ** 2 }
    return sum / (self.length - 1).to_f
  end

  def standard_deviation
    return Math.sqrt(self.sample_variance)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbkb-0.7.2 lib/rbkb/extends/enumerable.rb