Created
July 25, 2018 01:00
-
-
Save cefaijustin/644fe899b90c41d6b3f82e94de1894e7 to your computer and use it in GitHub Desktop.
Ruby Hash Table Exercise
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
module WordCounter | |
def self.count(string) | |
return nil if !string || string == "" | |
string = string.downcase.gsub(/[\n.,?()]/, '').split(" ") | |
string.each_with_object(Hash.new(0)) { |word, counts| counts[word] += 1} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment