Skip to content

Instantly share code, notes, and snippets.

@coolicer
Created July 5, 2012 04:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save coolicer/3051241 to your computer and use it in GitHub Desktop.
Javascript : Array distinct
/**
* Array distinct
* @param {Array} Array
* @return {Aaary} Return a new array without the same item
*/
var distinct = function(arr){
var i = 0,
l = arr.length,
v,t,o = {},n = [];
for(;i<l;i++){
v = arr[i],t = typeof v;
if(typeof o[v+t] == 'undefined'){
o[v+t] = 1;
n.push(v);
}
}
return n;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment