Created
June 23, 2015 16:28
-
-
Save tobie/b830e468061109d30470 to your computer and use it in GitHub Desktop.
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
function uniq(sortedArray) { | |
var output = []; | |
sortedArray.reduce(function(previous, current) { | |
if (current != previous) { | |
output.push(current); | |
} | |
return current; | |
}, null); | |
return output; | |
} | |
var arr = ["z", "a", "b", "c", "a", "a", "b"]; | |
arr.sort(); | |
uniq(arr); | |
// => ["a", "b", "c", "z"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment