From: Daniel Sheppard Date: 2006-06-05T15:40:17+09:00 Subject: Re: mode > -----Original Message----- > From: Elliot Temple [mailto:curi@curi.us] > > I bet there's a more elegant way to write this. Anyone want > to show me? > > def mode(li) ... > end It would probably help if you said what you were trying to achieve rather than asking people to try and interpret code that you admit isn't elegant. class Array def mode count = Hash.new(0) each {|x| count[x] += 1 } count.sort_by{|k,v|v}.last[0] end end