写贴一个有bug的代码:
function delR(obj){ var bo=Object.prototype.toString.call(obj).slice(8,-1)=="Array"? true:false; var temp=[]; if(bo){ for(var i=0;i<obj.length;i++){ if(temp.join().indexOf(obj[i])<0) temp.push(obj[i]); } } return temp; } delR([12,2])
代码二:
function f(arr){ var tmpArr=[]; var tmpObj={}; for(var i=0,len=arr.length; i<len; i++){ if(!tmpObj[arr[i]]){ tmpArr.push(arr[i]); tmpObj[arr[i]]="xx"; } } return tmpArr; }
代码三:
deleteRepeater: function (arr) { /// <summary> /// 删除当前数组中重复的项 /// </summary> /// <param name="arr"></param> /// <returns type=""></returns> if (arr.length < 2) return arr; var aT = arr.concat(); arr.length = 0; for (var i = 0; i < aT.length; i++) { arr.push(aT.splice(i--, 1)[0]); for (var j = 0; j < aT.length; j++) { if (aT[j]==arr[arr.length - 1]) aT.splice(j--, 1); } } return arr; }
代码四:
function distinct(src){ var arr = [], obj = {}, i = 0, len = src.length, result; for( ; i < len; i++ ){ result = src[i]; if( obj[result] !== result ){ arr.push( result ); obj[result] = result; } } return arr; }