Skip to content

Instantly share code, notes, and snippets.

@alekst
Created August 29, 2013 13:32
Show Gist options
  • Save alekst/6378167 to your computer and use it in GitHub Desktop.
Save alekst/6378167 to your computer and use it in GitHub Desktop.
Counts a number of identical elements within an array (word), returns them as a hash (counts). # {"foo" => 2, "bar" => 1}
def word_count
counts = Hash.new(0)
words.each do |word|
counts[word] += 1
end
return counts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment