Error: "can't convert String into Integer"


#1

Hello everyone!

The console show this message: "can't convert String into Integer", but the code is exactly like in example...

words = text.split(" ")
frequencies = Hash.new(0)

words.each do |word|
frequencies[word]+=1
frequencies = frequencies.sort_by { |k, v| v }
frequencies.reverse!
frequencies.each {|word, frequency| puts word+" "+frequency.to_s}
end


#2

Please post a link to this exercise. Thank you.


#3

https://www.codecademy.com/courses/ruby-beginner-pt-BR-b9rac/resume?curriculum_id=535951905d81961e16000001


#4

Move this line up to just under,

 frequencies[word]+=1

so it closes the do block, before the sort block.


#5

Thanks man :sweat_smile:


#6

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