Created
January 18, 2021 00:06
-
-
Save midknightmare666/f35e2bd46c815af2ea2f4334bd2e8ffe to your computer and use it in GitHub Desktop.
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
/** | |
* Remove all duplicate items from array | |
* | |
* @param {Array} array input array | |
* @returns {Array} an array of unique values | |
* | |
*/ | |
function unique (array) { | |
return [...array.reduce((acc, curr) => { | |
acc.add(curr); | |
return acc; | |
}, new Set())]; | |
} | |
/** | |
* example below | |
*/ | |
const result = unique([2, 1, 2]); | |
console.log(result); | |
// [2, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment