From: Phrogz Date: 2007-08-22T01:14:57+09:00 Subject: Re: Detecting duplicates in an array, anything in the standa On Aug 21, 10:04 am, Ari Brown wrote: > On Aug 21, 2007, at 4:59 AM, Pe�a, Botp wrote: > > > From: Robert Klemme [mailto:shortcut...@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 still think it's easier just to union itself... > > a = [1,2,3,2,1] > b = a & a > b = [1,2,3] ...but that's not what the OP wanted. What you've written is the same as the #uniq method. Don't feel bad, this thread has been filled with people answering the wrong question. :p The original question was roughly "How do I find out all the elements in the array that are duplicates?" Solutions to that question would not include '3' in the above results. It's unclear to me if %w| a b b b | should include 'b' once or twice in the output, though, and the original poster has not clarified that, that I can see.