Creating a Histogram Lockdown 6.0
Today was the first day of the 6th Lockdown for Melbourne. There is some solis in learning to code in amongst the crazy homeschooling and teaching. I also have a deadline to try to get this pre learning done by the end of August. My struggle is coming down to a lack of practice and getting stuck on blocks.
My Code today cuts up a string, creates an array and looks at the frequency of word in a given input
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 'Why are we in lockdown 6.0?' | |
text = gets.chomp | |
words = text.split | |
frequencies = Hash.new(0) | |
words.each do |word| | |
frequencies[word] += 1 | |
end | |
frequencies = frequencies.sort_by do |_word, count| | |
count | |
end | |
frequencies.reverse! | |
frequencies.each do |word, count| | |
# puts word + ' ' + count.to_s | |
puts "#{word} #{count}" | |
end |