Skip to content

Instantly share code, notes, and snippets.

@vpereira

vpereira/enum.cr Secret

Created January 3, 2018 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpereira/3595face7ed8988416f5cad8eb6ed31b to your computer and use it in GitHub Desktop.
Save vpereira/3595face7ed8988416f5cad8eb6ed31b to your computer and use it in GitHub Desktop.
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