Todd Benson
10/12/2008 4:58:00 AM
On Sat, Oct 11, 2008 at 10:50 PM, Tj Superfly <nonstickglue@verizon.net> wrote:
> Hey, I just have a quick question about arrays.
>
> I have two different ones that I would like to compare.
>
> Example:
>
> Array 1: cats, dogs, monkeys
>
> Array 2: cats, fish, dogs, birds, monkeys
>
> Now, I would like to compare array 2 with array 1 and have it spit out
> any words that aren't in both... if that makes sense.
>
> So what the program should output is fish, monkeys.
Hmm. I'm assuming you are looking for ["fish", "birds"], and if you
are, do union, then subtract intersection...
a = %w( cats dogs monkeys )
b = %w( cats fish dogs birds monkeys )
(a | b) - (a & b)
More than two arrays is left as an exercise :)
Todd