From: Andy Cooper Date: 2009-01-14T07:30:31+09:00 Subject: Re: Returning a duplicate from an Array > Andy Cooper wrote: > > > > 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. > > Thanks for the quick reply! However, after trying it, I found that > subtracting an array from an array will delete each instance of an > element, leaving me with a blank array, IE: > > [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] > > Any other ideas? > > Thanks again, > - Jeff Miller > -- Yeah, I am winning the typing contest today. > def dups(ary=[]) > uniq=ary.uniq > ary.reject{|z| if(uniq.include?(z));q-=[z];true;end} > end Should actually be def dups(ary=[]) uniq=ary.uniq ary.reject{|z| if(uniq.include?(z));uniq-=[z];true;end} end Made a mistake when I made q make more sense aparently. Andy Cooper