//
var arr=[1,2,2,2,2,4,2,2,2,4,2,22,2,];
var arr1=[1,1,1,1,1,1,1,1,1,1,1,4,4,2,2,1];
function diff(arr,arr1){
var a=[];var b=[];var r;
for(var i=0;i<arr.length;i++){
var index=arr1.indexOf(arr[i]);
if(index!=-1){
var r=a[i];
for(var j=index;j<arr1.length;j++){
if(arr1[j]==arr[i]){
arr1.splice(j,1);
j=j-1;
}
}
for(var k=i+1;k<arr.length;k++){
if(arr[k]==arr[i]){
arr.splice(k,1);
k=k-1;
}
}
arr.splice(i,1);
i=i-1;
}
}
return arr.concat(arr1);
}
var result=diff(arr,arr1);
console.log(result);