Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Created April 14, 2017 02:56
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 erkobridee/612a00a94b67671c9d757784a537b0d3 to your computer and use it in GitHub Desktop.
Save erkobridee/612a00a94b67671c9d757784a537b0d3 to your computer and use it in GitHub Desktop.
given a array of numbers, using Array.reduce return an array of uniques numbers
function unique(array) {
return array.reduce(function(acc, item){
if(!acc.find(function(element){ return element === item; })){
acc.push(item);
}
return acc;
}, []);
}
var numbers = [1,1,2,3,4,4];
console.log(unique(numbers)); // [1,2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment