Javascript字符串集函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript字符串集函数相关的知识,希望对你有一定的参考价值。
Exploits hash keys uniqueness, but in doing so effectively toString()s everything, meaning this should not be used for much beyond strings and perhaps integers.I used this when I wanted to do some client-side filtering of (integer) identifiers.
function unique(l) { var o=new Object(),ret=[]; for(i in l){o[l[i]]=1} for(k in o){ret.push(k)} return ret; } function union(l1,l2) { var o=new Object(),ret=[]; for(i in l1){o[l1[i]]=1} for(i in l2){o[l2[i]]=1} for(k in o){ret.push(k)} return ret; } function intersect(l1,l2) { var o=new Object(), ret=[]; for (i in l1) o[l1[i]]=1; //this value is ignored for (i in l2) if (o[l2[i]]!==undefined) ret.push(l2[i]); return ret; } function except(l1,l2) { var o=new Object(), ret=[]; for (i in l1) o[l1[i]]=1; for (i in l2) delete(o[l2[i]]); for (i in o) ret.push(i); return ret; }
以上是关于Javascript字符串集函数的主要内容,如果未能解决你的问题,请参考以下文章