Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_words(string)
- str = string.downcase
- str = str.gsub(/\b/, '-')
- words = str.scan(/-([a-z]+)-/)
- count = Hash.new(0)
- words.each do |word|
- count[word] += 1
- puts word
- end
- return count
- end
- c = count_words("This is a sentence")
- puts c, c["is"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement