Last active
June 7, 2025 11:22
-
-
Save sajaddp/966f4e3efa8d6c75b2ebb02eef068ed2 to your computer and use it in GitHub Desktop.
Removing Array Duplicates in ES6
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
const array = [1,2,3,3,5,4,8,9,5,2,3,1,2,2,1,1,3,6,4,8,9,1,2,5,3,4,6,9,7,8,9] as const; | |
const uniqueArray = Array.from(new Set(array)) satisfies typeof array; | |
const uniqueArray2 = array.reduceRight<number[]>((acc, cur) => acc.includes(cur) ? acc : [cur, ...acc], []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment