# Matching arrays within arrays

**URL:** <https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090>\
**Category:** Ruby\
**Created:** [January 23, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090 "2007-01-23T16:20:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [January 23, 2007, 4:20pm UTC](https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090/1 "2007-01-23T16:20:46Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [January 23, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090/2 "2007-01-23T16:24:50Z")

</div>

Nick B. wrote:

> 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”]]

---

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [January 23, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090/3 "2007-01-23T16:25:08Z")

</div>

Nick B. 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”]]

---

<div class="post-metadata">

**Author:** ![nicken](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/d07c76/32.png) [@nicken](https://www.ruby-forum.com/u/nicken)\
**Post date:** [January 23, 2007, 4:40pm UTC](https://www.ruby-forum.com/t/matching-arrays-within-arrays/83090/4 "2007-01-23T16:40:53Z")

</div>

Cheers!
