From: "David A. Black" Date: 2007-08-19T21:33:46+09:00 Subject: Re: Detecting duplicates in an array, anything in the standa --1926193751-1586217508-1187526827=:15294 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-1586217508-1187526827=:15294" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-1586217508-1187526827=:15294 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Sun, 19 Aug 2007, Wolfgang N=C3=A1dasi-Donner wrote: > David A. Black wrote: >> Hi -- >> >> On Sun, 19 Aug 2007, Wolfgang N=C3=A1dasi-Donner wrote: >> >>> : [r[0], r[1][1..-1]]}[0].uniq # =3D> ["c"] >> How about: >> >> >> a =3D [1,2,3,4,5,4,2,2] >> =3D> [1, 2, 3, 4, 5, 4, 2, 2] >> >> a.inject([]) {|acc,e| acc << e unless acc.include?(e); acc } >> =3D> [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, Sorry, just ignore me. I've reinvented Array#uniq :-) /me reaches for coffee.... David --=20 * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --1926193751-1586217508-1187526827=:15294-- --1926193751-1586217508-1187526827=:15294--