Skip to content

Instantly share code, notes, and snippets.

@caomulaodao
Last active August 29, 2015 14:07
Show Gist options
  • Save caomulaodao/82ed952f166077f15c51 to your computer and use it in GitHub Desktop.
Save caomulaodao/82ed952f166077f15c51 to your computer and use it in GitHub Desktop.
#数组去重
Array.prototype.unique = function(){
this.sort(); //先排序
var res = [this[0]];
for(var i = 1; i < this.length; i++){
if(this[i] !== res[res.length - 1]){
res.push(this[i]);
}
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment