mardi 22 septembre 2015

Find item in array that has most word frequency

I am trying to choose 2 values only without "Ten" keys.

word_frequency = Hash.new(0)

most_count = %w(Five Ten Six Eleven Ten Six One)

most_count.each {|word| word_frequency[word] += 1}
word_frequency.max_by { |k,v| v }

Result:

=> ["Ten", 2]

Aucun commentaire:

Enregistrer un commentaire