Skip to content

Instantly share code, notes, and snippets.

@tobie
Created June 23, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobie/b830e468061109d30470 to your computer and use it in GitHub Desktop.
Save tobie/b830e468061109d30470 to your computer and use it in GitHub Desktop.
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