Histogram problem


#1

Hi guys,

anyone able to tell me what is wrong with this...

puts "type something please"
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
 frequencies[word] += 1
words.each {|word| frequencies[word] +=1 }
frequencies = frequencies.sort_by { |x,y| y}
frequencies.reverse!
frequencies.each { |word, frequency| puts word + " " + frequency.to_s }
end

thanks in advance


#2

Remove the above line. You have it in the block, which is where it belongs.


#4

Thanks mtf,

You guys are so helpful...makes it a lot easier to learn!!!!


#5

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