Created
August 27, 2016 16:14
-
-
Save anonymous/ba7282377016e17c9a774ca32d39e918 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 a sentence." | |
text = gets.chomp | |
words = text.split | |
frequencies = Hash.new(0) | |
words.each do |x| | |
frequencies[x] += 1 | |
end | |
# | |
frequencies = frequencies.sort_by do |word| | |
word.count | |
end | |
OR | |
frequencies = frequencies.sort_by do |word, count| | |
count | |
end | |
# | |
frequencies.reverse! | |
puts frequencies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment