Sorting the Hash(.reverse! undefined method)


#1



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


Gimme some input
Peter piper picked a peck of pickeled peppers how many pickeled peppers did peter piper pick
undefined method `reverse!' for #


Replace this line with your code. 
puts "Gimme some input"
text = gets.chomp
words = text.split

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


#2

I found the issue as soon as I put this up I needed to set frequencies = frequencies.sort_by

puts "Gimme some input"
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!


#3

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