Last active
June 14, 2018 15:34
-
-
Save Renaud009/56dde2ac890db6bac109e354362cbc22 to your computer and use it in GitHub Desktop.
Test
This file contains 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 uniqSort = function(arr) { | |
const bread = {}; | |
const result = [arr[0]]; | |
for (let i = 1; i < arr.length; i++) { | |
if(!bread[arr[i]] { | |
result.push(arr[i]); | |
bread[arr[i]] = true; | |
} | |
} | |
return result.sort((a,b) => a - b); | |
} | |
uniqSort([4,2,2,2,3,2,2,2]) // => [2,3,4] | |
// Wait, what if... | |
uniqSort([4,4,2,2,3,2,2,2]) // => [2,3,4,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment