module Enumerable
Add methods to Enumerable
, which makes them available to Array
Public Instance Methods
mean()
click to toggle source
mean of an array of numbers
# File lib/maths.rb, line 9 def mean return self.sum/self.length.to_f end
sample_variance()
click to toggle source
variance of an array of numbers
# File lib/maths.rb, line 14 def sample_variance mean=self.mean sum=self.inject(0){|acc,i|acc +(i-mean)**2} return(1/self.length.to_f*sum) end
standard_deviation()
click to toggle source
standard deviation of an array of numbers
# File lib/maths.rb, line 21 def standard_deviation return Math.sqrt(self.sample_variance) end
sum()
click to toggle source
sum of an array of numbers
# File lib/maths.rb, line 4 def sum return self.inject(0){|acc,i|acc +i} end