danielharan (owner)

Revisions

gist: 27182 Download_button fork
public
Public Clone URL: git://gist.github.com/27182.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
# > {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