-
-
Save vpereira/3595face7ed8988416f5cad8eb6ed31b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def sum | |
self.reduce(0){|accum, i| accum + i } | |
end | |
def mean | |
self.sum/self.size.to_f | |
end | |
def variance | |
m = self.mean | |
sum = self.reduce(0){|accum, i| accum + (i-m)**2 } | |
sum/(self.size - 1).to_f | |
end | |
def stddev | |
return Math.sqrt(self.variance) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment