From: "pauldacus@..." Date: 2005-10-18T05:26:57+09:00 Subject: Re: How to get non-unique elements from an array? That is a good one. Personally, I was curious though when you said you thought regex-ing it was slower or 'too much', if it really would be on huge arrays. And so a test: (REGEX) a.sort.join(' ').to_s.scan(/(\d+)\s(\1)+/).flatten.uniq vs. (INDEX) a.select{|e| a.index(e) != a.rindex(e)}.uniq I ran these on an array with 11,000 elements, 2,000 of which were duplicates, as follows: (1..10000).to_a + (2000..3000).to_a The scan (REGEX) script finished in 0.21 seconds The (INDEX) script ran in 28.77 seconds The regex was over 100X faster! And I actually was trying to run this with 110,000 elements but the INDEX script seem to just lock up. The regex was done in 2.63 seconds, and the INDEX script was still going 10 minutes later.... Have no doubt... a scan is darn fast!