Skip to content

Instantly share code, notes, and snippets.

@danielharan
Created November 20, 2008 20:38
Show Gist options
  • Save danielharan/27182 to your computer and use it in GitHub Desktop.
Save danielharan/27182 to your computer and use it in GitHub Desktop.
# > {1 => 'a', 2 => 'b', 3 => 'a'}.values.histogram
# => {"a"=>2, "b"=>1}
class Array
def histogram
inject(Hash.new(0)) do |memo,value|
memo[value] += 1
memo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment