Sorting the hash


#1

I've been working on this all night and cannot seem to grasp what exactly is going on. I understand the histogram portion but the error message is really confusing me since i'm not trying to convert any string into an integer?

its stating that it can't convert string to integer?

puts "Input text please: "
text = gets.chomp
words = text.split
frequencies = Hash.new(0)
words.each do |words| frequencies[words] =+ 1 
frequencies[words] = frequencies.sort_by do |words, frequencies|
frequencies[words].reverse!
frequencies[words].frequencies.to_s
end
end


#2

Block parameters are typically a singular of the pluralized object.

words.each { |word| ... }

frequencies.each { |frequency| ... }

This addresses the variable name conflicts, but there are a few other errors in the posted code sample. See if you can make the first few adjustments and then let us have another go at your revised code.


#3

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