Hash value is not incrementing by 1?


#1

https://www.codecademy.com/courses/learn-ruby/lessons/create-a-histogram/exercises/iterating-over-the-array?action=lesson_resume

Hello,

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?
M.

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.reverse!

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



Replace this line with your code. 



#2

It depends on your input.

How many times does it find the same word?


#3

HA! got it now. Thanks a lot!


#4

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