Extract common entries in two arrays

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, how to get an array with just common entries from two arrays?:

array1 =3D ["q", "w", "e", "r", "t", "y"]
array2 =3D ["w", "t", "z"]

I want to get:

array_common =3D ["w", "t"]

I don0t find an ellegant and fast way to get it. Any help?
Thanks a lot.

=2D-=20
I=C3=B1aki Baz Castillo
 
I

Iñaki Baz Castillo

El Domingo, 15 de Marzo de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
Hi, how to get an array with just common entries from two arrays?:

array1 =3D ["q", "w", "e", "r", "t", "y"]
array2 =3D ["w", "t", "z"]

I want to get:

array_common =3D ["w", "t"]

array_common =3D array1 - (array1 - array2)
=3D> ["w", "t"]

:)


=2D-=20
I=C3=B1aki Baz Castillo
 
B

Ben Bleything

=A0 array1 =3D ["q", "w", "e", "r", "t", "y"]
=A0 array2 =3D ["w", "t", "z"]

I want to get:
=A0 array_common =3D ["w", "t"]

array_common =3D array1 - (array1 - array2)
=3D> ["w", "t"]

Easier:

array1 & array2
=3D> ["w", "t"]

Ben
 
H

Harry Kakueki

Hi, how to get an array with just common entries from two arrays?:

array1 =3D ["q", "w", "e", "r", "t", "y"]
array2 =3D ["w", "t", "z"]

I want to get:

array_common =3D ["w", "t"]

I don0t find an ellegant and fast way to get it. Any help?
Thanks a lot.

array1 & array2

Harry

--=20
A Look into Japanese Ruby List in English
http://www.kakueki.com/ruby/list.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top