Skip to content

Instantly share code, notes, and snippets.

@dallasmarlow
Created May 17, 2012 00:31
Show Gist options
  • Save dallasmarlow/2715177 to your computer and use it in GitHub Desktop.
Save dallasmarlow/2715177 to your computer and use it in GitHub Desktop.
enum math
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