Skip to content

Instantly share code, notes, and snippets.

@RienNeVaPlus
Last active June 11, 2021 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RienNeVaPlus/b06fe939e8c23fb375322d1deee52d20 to your computer and use it in GitHub Desktop.
Save RienNeVaPlus/b06fe939e8c23fb375322d1deee52d20 to your computer and use it in GitHub Desktop.
Filter duplicates from two dimensional array
function array2dUnique(arr: any[], index: number = 0){
return arr.filter((a, i1, $) => !$.find((b, i2) => i1 > i2 && a[index] === b[index]))
}
console.log(
array2dUnique([
[1],
[2],
[1]
])
) // [ [1], [2] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment