From: Ryan Davis Date: 2007-08-21T19:02:44+09:00 Subject: Re: Detecting duplicates in an array, anything in the standa On Aug 21, 2007, at 01:59 , Pe�a, Botp wrote: > From: Robert Klemme [mailto:shortcutter@googlemail.com] > # irb(main):002:0> a.uniq.select{|e| (a-[e]).size < a.size - 1} > > compare also, > > irb(main):056:0> b=a.dup > => [1, 1, 2, 2, 2, 4, 3] > irb(main):057:0> b.uniq.select{|e| (b.reject!{|f| f == e}).size > 1} > => [1, 2] I came up with something vaguely similar: class Array def dupes a = self.dup self.partition { |o| a.delete(o) }.last end end >> [1,2,2,3,4,4].dupes => [2, 4]