From: Trans Date: 2008-10-01T08:33:49+09:00 Subject: Re: Mode method for Array On Sep 30, 5:56 pm, Glenn wrote: > Hi, > > I'd like to write a get_mode method for the Array class.  The method would return an array of the most frequently occurring element or elements. > > So [3, 1, 1, 55, 55].get_mode would return [1, 55]. > > I have a way to do this but I don't know if it's the best way.  I was wondering if anyone had any suggestions? Facets has: module Enumerable # In Statistics mode is the value that occurs most # frequently in a given set of data. def mode count = Hash.new(0) each {|x| count[x] += 1 } count.sort_by{|k,v| v}.last[0] end end Hmm.. but that thwarts ties. I'll have to consider how to fix. T.