Skip to content

Instantly share code, notes, and snippets.

@midknightmare666
Created January 18, 2021 00:06
Show Gist options
  • Save midknightmare666/f35e2bd46c815af2ea2f4334bd2e8ffe to your computer and use it in GitHub Desktop.
Save midknightmare666/f35e2bd46c815af2ea2f4334bd2e8ffe to your computer and use it in GitHub Desktop.
/**
* 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