Created
May 7, 2011 22:39
-
-
Save mrc/960919 to your computer and use it in GitHub Desktop.
Histogram (tweeted by mfeathers)
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 is awesome! | |
module Enumerable; | |
def histogram; | |
groups = group_by {|i| i}; | |
(0..max).map {|bin| (groups[bin] || []).count} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby "module" extends all Enumerable class objects with a histogram function. Gosh!