校招题目之多个数组取唯一值
fakefish opened this issue · 0 comments
fakefish commented
function array_diff(){
var arr,result,tab,index;
result=[];
tab=[{
value:'',
num:''
}];
for(var i=0,len=arguments.length;i<len;i++){
arr = arguments[i];
for(var j=0,l=arr.length;j<l;j++){
index=-1;
if(!isNaN(arr[j])){
for(var x=0;x<tab.length;x++){
if(arr[j]===tab[x].value){
index=x;
}
}
if(index==-1){
tab.push({
value:arr[j],
num:1
});
}else{
tab[index].num+=1;
}
}
}
}
for(i=0,len=tab.length;i<len;i++){
if(tab[i].num==1){
result.push(tab[i].value);
}
}
return result;
}
console.log(array_diff( [1, 2, 3, 'a'], [2, 3, 4, 'b'], [3, 4, 5, 'd']));