From: Joel VanderWerf Date: 2008-09-16T06:04:43+09:00 Subject: Re: array question Nathan Powell wrote: > On Tue, Sep 16, 2008 at 05:27:03AM +0900, Li Chen wrote: ... >> 2)Is there mentod in Array class that can return the element only >> unique to either of two arrays? > > http://ruby-doc.org/core/classes/Array.html > >> For example, array1=[1,2,3],array2=[1,4,7] >> the return array is [2,3,4,7] > > > There might be a better way, but I came up with: > >>> ([1, 2, 3] - [1, 4, 7]) + ([1, 4, 7] - [1, 2, 3]) > => [2, 3, 4, 7] > Or: (a1|a2) - (a1&a2) Or: require 'set' Set.new(a1) ^ Set.new(a2) (I thought I remem