Hello
I guess something is wrong with the code, although the exercise is validated, because my words are not appearing in any specific order ( ascendant or descendant), only by the order as they appear in the sentence.
This is my code :
puts "Your text here : "
text = gets.chomp
words = text.split (" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }
puts frequencies
# {}
puts frequencies ["rate"]
# 0
frequencies = frequencies.sort_by {|a, b| b}
frequencies.reverse!
And this is the result I get :
Your text here :
racoon racoon elephant potato tomato tomato tomato
{"racoon"=>2, "elephant"=>1, "potato"=>1, "tomato"=>3}
0
I tried without the frequencies.reverse!
, and I get the exact same result.
Can someone help me to see whatโs wrong ?
Thank you !