Histogram problem


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.each { |word, frequency| puts word + " " + frequency.to_s }

thanks in advance


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


Thanks mtf,

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


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