Last active
October 31, 2015 06:13
-
-
Save kkchu791/6cc027c326a6812f6880 to your computer and use it in GitHub Desktop.
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
def word_count(sentence) | |
hash = sentence.downcase.gsub(/\W+/, ' ').split(" ").group_by{ |item| item } | |
hash.each { |item| hash[item[0]] = item[1].length } | |
end | |
p word_count("The quick brown fox jumped over the moon. This mammal did not jump over the sun; it jumped over the moon. And it was quick about it.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instead of this:
sentence.downcase.gsub(/\W+/, ' ').split(" ").group_by{ |item| item }
Some of our folks figured out this
sentence.downcase.split(/\W+/).group_by{ |item| item }