Last active
April 20, 2016 05:00
-
-
Save Rukomoynikov/0f125029a81b8efe8231ad6563fc02f2 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
# TOP 10 of most frequently words | |
words = Hash.new(0); | |
File.foreach('./text.txt') do |line| | |
line.split(' ').each do |word| | |
formattedWord = word.gsub(/[\W]/, "").downcase | |
words[formattedWord] += 1 | |
end | |
end | |
words = words.sort_by{ |word| word[1]}.reverse() | |
File.open("./beauty_of_word.txt", "w") do |io| | |
counter = 0 | |
words.each do |count, word| | |
break if counter == 10 | |
counter += 1 | |
io.puts "Слово #{word} встречается #{count} раз" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment