Last active
March 19, 2018 15:34
-
-
Save ysnerdem/a240e0e3647fd785fb2ccdd7ce7c1641 to your computer and use it in GitHub Desktop.
Word Frequency Counter
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_freq_counter(text, word) | |
counter = 0 | |
text = text.downcase.split(/\W+/) | |
text.each {|w| counter += 1 if w == word} | |
counter | |
end | |
text = gets.chomp | |
word = gets.chomp.downcase | |
puts word_freq_counter(text, word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment