Skip to content

Instantly share code, notes, and snippets.

@richdownie
Created April 14, 2011 00:56
Show Gist options
  • Save richdownie/918735 to your computer and use it in GitHub Desktop.
Save richdownie/918735 to your computer and use it in GitHub Desktop.
1 (histo)grams of phat
array = %w( maxfli maxfli maxfli titleist callaway titleist nike titleist callaway maxfli )
=> ["maxfli", "maxfli", "maxfli", "titleist", "callaway", "titleist", "nike", "titleist", "callaway", "maxfli"]
h = Hash.new(0)
=> {}
array.each do |word|
h[word] += 1
end
=> ["maxfli", "maxfli", "maxfli", "titleist", "callaway", "titleist", "nike", "titleist", "callaway", "maxfli"]
h
=> {"maxfli"=>4, "titleist"=>3, "callaway"=>2, "nike"=>1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment