From: "Wolfgang Nádasi-Donner" Date: 2007-08-19T21:06:54+09:00 Subject: Re: Detecting duplicates in an array, anything in the standa David A. Black wrote: > Hi -- > > On Sun, 19 Aug 2007, Wolfgang Nádasi-Donner wrote: > >> : [r[0], r[1][1..-1]]}[0].uniq # => ["c"] > How about: > > >> a = [1,2,3,4,5,4,2,2] > => [1, 2, 3, 4, 5, 4, 2, 2] > >> a.inject([]) {|acc,e| acc << e unless acc.include?(e); acc } > => [1, 2, 3, 4, 5] > > > David The problem is, that he wants all non unique elements. Unfortunately the difference of two arrays doesn't care about double elements, otherwise... irb(main):004:0> a => [1, 2, 3, 4, 5, 4, 2, 2] irb(main):005:0> b => [1, 2, 3, 4, 5] irb(main):006:0> a-b => [] ...would work. My solution is not recommended at all - it's sunday after lunch time, and I had the decision between cleaning the dishes or to do some nice things before... Wolfgang Nádasi-Donner -- Posted via http://www.ruby-forum.com/.