tags:

views:

34

answers:

1

Is there a way to compare two arrays and show what is common to both of them?

array1 = ["pig", "dog", "cat"]
array2 = ["dog", "cat", "pig", "horse"]
????    

What do I type to show that ["pig", "dog", "cat"] are common between these two arrays?

+2  A: 

You can intersect the arrays using

array1 & array2

This will return ["pig", "dog", "cat"]

Raoul Duke
Thank you :) I'm obviously a noob.
No problem. Could you also please accept the answer if you're completely satisfied with it? It will make it easier for people to see that the problem is solved (and I will get some rep :))
Raoul Duke
Yep. Just had to wait 10 minutes :)