Skip to content

Instantly share code, notes, and snippets.

@nire0510
Created April 4, 2018 12:17
Show Gist options
  • Save nire0510/5cd2aec6c0301ad3914bbb93ba45198c to your computer and use it in GitHub Desktop.
Save nire0510/5cd2aec6c0301ad3914bbb93ba45198c to your computer and use it in GitHub Desktop.
Returns array which each of its elements appears only once
const arr = [1, 2, 2, 8, 5, 5, 3, 8, 3];
arr.sort().reduce((a, c) => {
if (a.includes(c)) {
return a;
}
a.push(c);
return a;
}, []);
// -> [1, 2, 3, 5, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment