Sorting the Hash - Help understanding


#1


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

I'm trying to understand why my code will work with some text, but not others:


puts "Print text"
text = gets.chomp
words = text.split " "

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


#2

words = text.split(" ")

should be += 1.


#3

Thank you! That seems to have resolved my issue. Interesting that it would give me the green light with the incorrect syntax. @mtf


#4

The SCT is only a 'soft' test for correct elements in the code. It often ignores console errors.