Skip to content

Instantly share code, notes, and snippets.

@cefaijustin
Created July 25, 2018 01:00
Show Gist options
  • Save cefaijustin/644fe899b90c41d6b3f82e94de1894e7 to your computer and use it in GitHub Desktop.
Save cefaijustin/644fe899b90c41d6b3f82e94de1894e7 to your computer and use it in GitHub Desktop.
Ruby Hash Table Exercise
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