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

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