# Dedupe an array of arrays based on a common key/object with formulamap()

**URL:** <https://connect.superhuman.com/t/dedupe-an-array-of-arrays-based-on-a-common-key-object-with-formulamap/15936>\
**Category:** Ask the Community\
**Created:** [May 14, 2020, 11:08pm UTC](https://connect.superhuman.com/t/dedupe-an-array-of-arrays-based-on-a-common-key-object-with-formulamap/15936 "2020-05-14T23:08:23Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![Paul\_Danyliuk](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/paul_danyliuk/32/27228_2.png) [@Paul\_Danyliuk](https://connect.superhuman.com/u/Paul_Danyliuk)\
**Post date:** [May 16, 2020, 4:03pm UTC](https://connect.superhuman.com/t/dedupe-an-array-of-arrays-based-on-a-common-key-object-with-formulamap/15936/16 "2020-05-16T16:03:35Z")

</div>

Alright, here’s an explanation (also noticed a problem with my solution while writing this post, lol, so fixed and also simplified).

Normally the solution would look like this:

1. Get the list of unique emails as

2. Run a simple formula map:

But I guess you can see the problem already. Since the `CurrentValue` variable is overwritten within `Filter()` with a record from the list of lists, there’s no way to access the outer `CurrentValue` that would mean the current email to find records for.

So the trick here is to make a full product of M emails and N records and then filter/slice based on that. This way we can iterate over all combinations of inner and outer `CurrentValue` (because our `CurrentValue` will essentially be a `List(OuterCurrentValue, InnerCurrentValue)`. And because of the cyclic nature of this new list (items 1…N correspond to 1st email, items N+1…2N correspond to 2nd email etc) it’s easy to extract and only use the portion of the list we’re interested in within this iteration.

So here’s what I’m doing:

1. Inner and outer count. This is straightforward:  
 ![image](https://global.discourse-cdn.com/coda1/original/2X/6/6153db5545aa893a2947492f0161891219ed9dc1.png)

2. I’m composing a full product of two lists, i.e. all combinations of items from the right and items from the left here:  

3. In the same cell (because why not) I’m replacing items where the join fails (i.e. email `CurrentValue.First()` doesn’t match the one in the record `CurrentValue.Last().Last()`) with blanks, and unwrapping the rest:  

4. So all that’s left is to select one record from each sequence of N items:

Hope this explains the trick. There’s not much genius in this — I think any person with some CS and competitive programming background would’ve considered this approach.

---

_[View the full topic](https://connect.superhuman.com/t/dedupe-an-array-of-arrays-based-on-a-common-key-object-with-formulamap/15936)._
