Skip to content

Instantly share code, notes, and snippets.

@ysnerdem
Last active March 19, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysnerdem/a240e0e3647fd785fb2ccdd7ce7c1641 to your computer and use it in GitHub Desktop.
Save ysnerdem/a240e0e3647fd785fb2ccdd7ce7c1641 to your computer and use it in GitHub Desktop.
Word Frequency Counter
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