From: "RĂ¼diger Brahns" Date: 2008-10-12T23:37:30+09:00 Subject: Re: Compare Arrays Todd Benson schrieb: > On Sat, Oct 11, 2008 at 10:50 PM, Tj Superfly 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) Why not just b - a ? But as I understand him what he wants is a & b