From: Park Heesob Date: 2005-10-18T10:13:41+09:00 Subject: Re: How to get non-unique elements from an array? Hi, >> >> On second thought, Mark's may have been the best overall. Either way, >> both Mark's and Martin's are good algorithms. Many of the others were >> good as well. >> > > Mine isn't the shortest, but it's the fastest I've seen thus far! Twice > as fast as the next closest! Why does everyone leave me out of benchmark, > ;) > > ---my code > t=[]; a.delete_if{ |e| r=(not t.include? e); t.push(e); r } > ---end my code > > Zach > Here is my code t = Hash.new(0); a.each{|e|t[e]+=1};t.delete_if{|k,v|v==1}.keys It is reasonably fast for both small and large arrays small array zach 0.328000 0.000000 0.328000 ( 0.328000) markvh 0.390000 0.000000 0.390000 ( 0.390000) martin 0.422000 0.000000 0.422000 ( 0.422000) xxx 0.344000 0.000000 0.344000 ( 0.344000) <== MINE large array zach 2.204000 0.000000 2.204000 ( 2.203000) markvh 0.015000 0.000000 0.015000 ( 0.016000) martin 0.000000 0.000000 0.000000 ( 0.000000) xxx 0.000000 0.000000 0.000000 ( 0.000000) <== MINE Park Heesob