Last active
August 4, 2016 11:18
-
-
Save wolfhesse/4d55bf54f4f39a773d8a899c2034b5da to your computer and use it in GitHub Desktop.
:ruby :scratchpad
This file contains hidden or 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
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end | |
class Array; def mean; sum / size; end; end | |
class Array; def sd; m=mean; Math.sqrt(collect{|e|(m-e)**2}.mean); end; end |
This file contains hidden or 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
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end | |
class Array; def mean; sum / size; end; end | |
def sd(population) | |
m=population.mean | |
Math.sqrt(population.collect{|e|(m-e)*(m-e)}.mean) | |
end | |
set=[2,4,4,4,5,5,7,9] | |
puts sd(set) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment