Created
September 13, 2016 14:04
-
-
Save MattPorto/7e62c2e301034610942a95216211a936 to your computer and use it in GitHub Desktop.
recebe um texto e conta quantas vezes cada palavra apareceu no texto
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 "Digite o texto:" | |
text = gets.chomp | |
words = text.split(" ") | |
frequencies = Hash.new(0) | |
words.each { |x| frequencies["#{x}"] += 1} | |
frequencies = frequencies.sort_by do |word, count| | |
count | |
end | |
frequencies.reverse! | |
frequencies.each { |word, count| puts word + " " + count.to_s} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment