-
-
Save dallasmarlow/2715177 to your computer and use it in GitHub Desktop.
enum math
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 :+ | |
end | |
def mean | |
self.sum / self.size | |
end | |
def median | |
self.sort[self.size / 2] | |
end | |
def variance | |
average = self.mean | |
self.reduce {|deviation_sum, value| deviation_sum + (value - average) ** 2} / self.size | |
end | |
def standard_deviation | |
Math.sqrt self.variance | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment