Sorting the hash help me!


#1

My code is not working, why?? take a look

puts "Type your text: "
text = gets.chomp

words = text.split

frequencies = Hash.new(0)

frequencies = frequencies.sort_by { |words, count| count }

words.each {|count| frequencies[count] += 1}


frequencies.reverse!

Error: Oops, try again. It looks like you haven't set the frequencies hash correctly. Check the first exercise if you need help!


#2
frequencies = Hash.new(0)

This means the hash is empty right?

frequencies = frequencies.sort_by { |words, count| count }

Then why are you asking to sort it?

Fill the hash first.


#3

Ohh that's true. I changed the position of 3ยบ line to after the line 'words.each...' then it worked!!

Thank you!!