Last active
August 29, 2015 14:06
-
-
Save clinyong/07a92287bfb1182aa5eb to your computer and use it in GitHub Desktop.
数组去重
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//这个函数还有个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