Hash value is not incrementing by 1?




I passed all the tests in this exercise. It seems, my code is the same as everyones,
but when I print out the Hash values, they are all equal to 1. It does not seem right?
Can anybody explain please?

puts "input pls: "
text = gets.chomp
words = text.split()

frequencies = Hash.new(0)

words.each {|word| frequencies[word] +=1}

frequencies = frequencies.sort_by {|word, value| value}


frequencies.each {|key,value| puts key + " " + value.to_s}

Replace this line with your code. 


It depends on your input.

How many times does it find the same word?


HA! got it now. Thanks a lot!


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