Last active
June 11, 2021 23:46
-
-
Save RienNeVaPlus/b06fe939e8c23fb375322d1deee52d20 to your computer and use it in GitHub Desktop.
Filter duplicates from two dimensional array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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