Created
June 11, 2020 09:11
-
-
Save kirhgoff/ccf8af3d482f35168f1fbe773eca4b46 to your computer and use it in GitHub Desktop.
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
puts "Type something to count words in: " | |
frequencies = Hash.new(0) | |
text = gets.chomp.downcase! | |
text = text.gsub!(/[^A-Za-z ]/, '') #This removes punctuation | |
text.split | |
.each { |word| frequencies[word] += 1 } | |
.sort_by { |word, count| count } | |
.reverse | |
.each { |word, count| puts "#{word} #{count}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment