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
# Add sum, mean, & median to Array class | |
class Array; def sum; inject(:+) end end | |
class Array; def mean; sum.to_f / size end end | |
class Array | |
def median(arry) | |
sorted = arry.sort | |
medpt = arry.length / 2 | |
medpt1 = ( ( arry.length - 1 ).to_f / 2 ) | |
(sorted[medpt] + sorted[medpt1]).to_f / 2 | |
end |
NewerOlder