From: Rob Biedenharn Date: 2008-09-16T05:53:43+09:00 Subject: Re: array question On Sep 15, 2008, at 4:42 PM, Nathan Powell wrote: > On Tue, Sep 16, 2008 at 05:27:03AM +0900, Li Chen wrote: >> Hi all, >> >> Just wonder: >> >> 1)When substracting array2 from array1 to get the difference elements >> between two arrays(array1-array2), must array1.size >= array2? > > irb is great for this stuff. > >>> [1, 2] - [1, 3, 4] > => [2] > >> 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] > > -- > nathan > nathan_at_nathanpowell_dot_org > > What kind of crazy nut would spend two or three hours a day just > running? > ~ Steve Prefontaine > ------------------------------------ irb> (a1 | a2) - (a1 & a2) => [2, 3, 4, 7] -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com