Iterating Over the Hash - Create a Histogram


#1


Link to the Lesson

Error Message:

Oops, try again. It looks like you aren't printing each key-value pair to the console correctly. Make sure to put a space between each key and value!

I'm having serious trouble with this lesson and have been stuck on it for around a week. I've tried almost everything I can think of: clearing the cache, changing browsers, editing the code a bit, and using other packs of code from this forum. None of them work. Thus, I am asking for desperately needed help in this section (mostly if my code works for other people).


code:


puts "text"
text = gets.chomp

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


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.