Module: Enumerable

Included in:
TextBoxParser
Defined in:
lib/enumerable_extenders.rb

Instance Method Summary collapse

Instance Method Details

#arraysumObject

sum of an array of numbers



7
8
9
# File 'lib/enumerable_extenders.rb', line 7

def arraysum
  return self.inject(0){|acc,i|acc +i}
end

#averageObject

average of an array of numbers



12
13
14
# File 'lib/enumerable_extenders.rb', line 12

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

#dupsObject



2
3
4
# File 'lib/enumerable_extenders.rb', line 2

def dups
  inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end

#sample_varianceObject

variance of an array of numbers



17
18
19
20
21
# File 'lib/enumerable_extenders.rb', line 17

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_deviationObject

standard deviation of an array of numbers



24
25
26
# File 'lib/enumerable_extenders.rb', line 24

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