Skip to content

Instantly share code, notes, and snippets.

@clinyong
Last active August 29, 2015 14:06
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 clinyong/07a92287bfb1182aa5eb to your computer and use it in GitHub Desktop.
Save clinyong/07a92287bfb1182aa5eb to your computer and use it in GitHub Desktop.
数组去重
//这个函数还有个bug,就是当输入的数组为[new String(1), new Number(1)]时,无法区别
function uniqueArr(arr) {
var n = {};
var r = [];
arr.forEach(function(v){
var key = typeof(v) + v;
if (!n[key]) {
n[key] = true
r.push(v)
}
})
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment