Confuse on these code


#1



puts "What is your favourite food?"
text = gets.chomp

words = text.split

frequencies = Hash.new(0)

words.each {|word| frequencies[word] += 1}
frequencies = frequencies.sort_by {|a,b| b}
frequencies.reverse!

Question:
What is {|a,b| b} means in the above code? Can someoneexplain in details?


Replace this line with your code.


Hi, i dont understand
#2

frequencies is a hash containing key and value, when calling sort upon the hash we call keys a and values b. we want to sort on the values, so we choose b.
its like calling .each where you would use the same structure.


#3

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