[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

matching arrays within arrays

Nick Black

1/23/2007 3:20:00 PM

Hello,

I have a number of arrays within arrays. Some of them are duplicatess like:

[[foo, bar, ru, by], [ru], [bar, foo], [foo, bar, ru, by]]

I would like to remove duplicates to end up with:

[[foo, bar, ru, by], [ru], [bar, foo]]

Is there a Ruby function to do this?


Cheers,


--
Nick Black
--------------------------------
http://www.black...

3 Answers

Alex Young

1/23/2007 3:24:00 PM

0

Nick Black wrote:
> Hello,
>
> I have a number of arrays within arrays. Some of them are duplicatess
> like:
>
> [[foo, bar, ru, by], [ru], [bar, foo], [foo, bar, ru, by]]
>
> I would like to remove duplicates to end up with:
>
> [[foo, bar, ru, by], [ru], [bar, foo]]
>
> Is there a Ruby function to do this?

irb(main):007:0> [['foo', 'bar', 'ru', 'by'], ['ru'], ['bar', 'foo'],
['foo', 'bar', 'ru', 'by']].uniq
=> [["foo", "bar", "ru", "by"], ["ru"], ["bar", "foo"]]

--
Alex

Chris Gernon

1/23/2007 3:25:00 PM

0

Nick Black wrote:
> Is there a Ruby function to do this?

uniq will work. It doesn't matter what type of object the members of the
array are, so it can be used for an array of arrays.

irb> [['foo', 'bar', 'ru', 'by'], ['ru'], ['bar', 'foo'], ['foo', 'bar',
'ru', 'by']].uniq
=> [["foo", "bar", "ru", "by"], ["ru"], ["bar", "foo"]]

--
Posted via http://www.ruby-....

Nick Black

1/23/2007 3:40:00 PM

0

Cheers!

On 1/23/07, Chris Gernon <kabigon@gmail.com> wrote:
> Nick Black wrote:
> > Is there a Ruby function to do this?
>
> uniq will work. It doesn't matter what type of object the members of the
> array are, so it can be used for an array of arrays.
>
> irb> [['foo', 'bar', 'ru', 'by'], ['ru'], ['bar', 'foo'], ['foo', 'bar',
> 'ru', 'by']].uniq
> => [["foo", "bar", "ru", "by"], ["ru"], ["bar", "foo"]]
>
> --
> Posted via http://www.ruby-....
>
>


--
Nick Black
--------------------------------
http://www.black...