From: Andy Cooper Date: 2009-01-14T07:18:55+09:00 Subject: Re: Returning a duplicate from an Array > > Hey guys, > > I have an array of names that may contain duplicates. What I > > would like > > to do is return an array OF THE DUPLICATES. I was looking around at > > various built-in methods for arrays, but the closest thing I > > can find is > > Array.uniq, which returns the array without the duplicates. > > > > Any suggestions on how to do this? > > > > Thanks, > > - Jeff Miller > > -- > > Without really looking into it a quick and dirty way would be to just > subtract the results of .uniq from the initial array. > > Andy Cooper. Nevermind that wont work afterall, wasn't thinking about how arrays work at the time. def dups(ary=[]) uniq=ary.uniq ary.reject{|z| if(uniq.include?(z));q-=[z];true;end} end There that should do the trick. Still very probably not the best of ways to do it though. Andy Cooper.