Create a Histogram: 7. Iterating over the hash -- Help!? --


#1

Okay, I've been on this lesson for way too long now... I've read every post on this forum discussing this one, referred back to every last step and "hint", but my code isn't working and I'm finally throwing in the towel... somebody please help :expressionless:

Here is my code:

puts "Say something... "
text = gets.chomp

words = text.split (" ")

frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {[word, frequency]}
frequencies.reverse!
frequencies.each do |word, frequency|
puts word + " " + frequency.to_s
end

....AND here is the error I am getting repeatedly. Or at least, the best error I'm getting. I've made many changes, some of which yielded in worse errors, so this seems to be the cleanest my code has gotten.


#2

This is where the error is thrown. The block parameter should be written between two pipes, not in an array.

... =  ... .sort_by {|word, frequency|}

#3

Wow, THANK YOU... .You have no idea how long I had been staring at that code.