Get common entries in two arrays

Hi, is there a way to generate a new array with the common elements in
array A and arra B? This is:

  arrayA = ["qqq", "www", "eee"]
  arrayB = ["www", "eee", "rrr", "ttt"]

the result should be: ["www", "eee"]

Thanks a lot.

···

--
Iñaki Baz Castillo
<ibc@aliax.net>

Of course I mean a method which perhaps I miss in Array class. If not,
I can do it manually :slight_smile:

···

2011/7/19 Iñaki Baz Castillo <ibc@aliax.net>:

Hi, is there a way to generate a new array with the common elements in
array A and arra B? This is:

arrayA = ["qqq", "www", "eee"]
arrayB = ["www", "eee", "rrr", "ttt"]

the result should be: ["www", "eee"]

--
Iñaki Baz Castillo
<ibc@aliax.net>

ruby-1.8.7-p334 :001 > arrayA = ["qqq", "www", "eee"]
=> ["qqq", "www", "eee"]
ruby-1.8.7-p334 :002 > arrayB = ["www", "eee", "rrr", "ttt"]
=> ["www", "eee", "rrr", "ttt"]
ruby-1.8.7-p334 :003 > arrayA & arrayB
=> ["www", "eee"]

Jesus.

···

On Tue, Jul 19, 2011 at 12:14 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:

Hi, is there a way to generate a new array with the common elements in
array A and arra B? This is:

arrayA = ["qqq", "www", "eee"]
arrayB = ["www", "eee", "rrr", "ttt"]

the result should be: ["www", "eee"]

arrayC = arrayA & arrayB

···

On 19 juil. 2011, at 12:14, Iñaki Baz Castillo wrote:

Hi, is there a way to generate a new array with the common elements in
array A and arra B? This is:

arrayA = ["qqq", "www", "eee"]
arrayB = ["www", "eee", "rrr", "ttt"]

the result should be: ["www", "eee"]

--
Luc Heinrich - luc@honk-honk.com

arrayA | arrayB should do the trick

···

2011/7/19 Iñaki Baz Castillo <ibc@aliax.net>

2011/7/19 Iñaki Baz Castillo <ibc@aliax.net>:
> Hi, is there a way to generate a new array with the common elements in
> array A and arra B? This is:
>
> arrayA = ["qqq", "www", "eee"]
> arrayB = ["www", "eee", "rrr", "ttt"]
>
> the result should be: ["www", "eee"]

Of course I mean a method which perhaps I miss in Array class. If not,
I can do it manually :slight_smile:

--
Iñaki Baz Castillo
<ibc@aliax.net>

Ops, great :slight_smile:

Thanks a lot.

···

El día 19 de julio de 2011 12:19, Jesús Gabriel y Galán <jgabrielygalan@gmail.com> escribió:

ruby-1.8.7-p334 :001 > arrayA = ["qqq", "www", "eee"]
=> ["qqq", "www", "eee"]
ruby-1.8.7-p334 :002 > arrayB = ["www", "eee", "rrr", "ttt"]
=> ["www", "eee", "rrr", "ttt"]
ruby-1.8.7-p334 :003 > arrayA & arrayB
=> ["www", "eee"]

--
Iñaki Baz Castillo
<ibc@aliax.net>

damn. arrayA & arrayB is it.

···

2011/7/19 Gunther Diemant <g.diemant@gmx.net>

arrayA | arrayB should do the trick

2011/7/19 Iñaki Baz Castillo <ibc@aliax.net>

2011/7/19 Iñaki Baz Castillo <ibc@aliax.net>:
> Hi, is there a way to generate a new array with the common elements in
> array A and arra B? This is:
>
> arrayA = ["qqq", "www", "eee"]
> arrayB = ["www", "eee", "rrr", "ttt"]
>
> the result should be: ["www", "eee"]

Of course I mean a method which perhaps I miss in Array class. If not,
I can do it manually :slight_smile:

--
Iñaki Baz Castillo
<ibc@aliax.net>

That would be the union. He's looking for Array#&

Jesus.

···

On Tue, Jul 19, 2011 at 12:19 PM, Gunther Diemant <g.diemant@gmx.net> wrote:

arrayA | arrayB should do the trick