Created
April 4, 2018 12:17
-
-
Save nire0510/5cd2aec6c0301ad3914bbb93ba45198c to your computer and use it in GitHub Desktop.
Returns array which each of its elements appears only once
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 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