Confuse on these code


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

words = text.split

frequencies =

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

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

Replace this line with your code.

Hi, i dont understand

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.


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