6 Sorting the Hash


#1

This is my code and it won't work.

puts "Enter text please: "
text = gets.chomp
words = text.split
frequencies=Hash.new(0)
words.each = {|word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|word, count| count}
frequencies.reverse!


#2

@tyler.w17945

should be


words = text.split(" ")

because it's a function


#3

Actually, the two forms are identical. When splitting on ' ', we may write text.split or text.split(' '). Both are correct and valid.


#4

Is there a question being asked here?