Sha256: 44fd86503be8aa9a6f7d7aaf601093f900f567e2480a6254a6cf28face95b886

Contents?: true

Size: 597 Bytes

Versions: 6

Compression:

Stored size: 597 Bytes

Contents

module Enumerable
  def dups
    inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
  end
 
  #  sum of an array of numbers
  def arraysum
    return self.inject(0){|acc,i|acc +i}
  end
 
  #  average of an array of numbers
  def average
    return self.sum/self.length.to_f
  end
 
  #  variance of an array of numbers
  def sample_variance
    avg=self.average
    sum=self.inject(0){|acc,i|acc +(i-avg)**2}
    return(1/self.length.to_f*sum)
  end
 
  #  standard deviation of an array of numbers
  def standard_deviation
    return Math.sqrt(self.sample_variance)
  end
 
  
end


Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
upgrade_surveyor_gui-0.1.3 lib/enumerable_extenders.rb
upgrade_surveyor_gui-0.1.2 lib/enumerable_extenders.rb
surveyor_gui-0.1.2 lib/enumerable_extenders.rb
surveyor_gui-0.1.1 lib/enumerable_extenders.rb
surveyor_gui-0.1.0 lib/enumerable_extenders.rb
surveyor_gui-0.0.3 lib/enumerable_extenders.rb