6. Sorting the hash


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-693PD/0/6?curriculum_id=5059f8619189a5000201fbcb


Having trouble passing this question. Am using the text below. Any suggestions?

Error message: undefined local variable or method `frequencies' for #


puts "Can I have some text?"
text = gets.chomp
words = text.split

words.each { |word| frequencies[word] += 1}
frequencies = Hash.new(0)
frequencies = frequencies.sort_by {|k, v| v}
frequencies.reverse!

#2

Hint: You first buy bananas (define variables) from the market before trying to eat them (use those variables) (or else you'll bite your hand (get an error))

Refer bananas (code):

words.each { |word| frequencies[word] += 1}
frequencies = Hash.new(0)

#5

"You first buy bananas (define variables) from the market before trying to eat them (use those variables) (or else you'll bite your hand (get an error)"

Like the analogy !


#6

Thanks :slight_smile: