1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| function findInArr(arr,str){ for(var i = 0; i<arr.length;i++){ if(arr[i] == str){ return true; } } return false; } var arr = [1,2,3,3,21,32,21,21]; function dup(arr,s,e){ if(s>e){ return []; } else if(s == e){ return [arr[s]]; } var c = Math.floor((s+e)/2); var l = dup(arr,s,c); var r = dup(arr,c+1,e); var arr2 = []; for(var i = 0;i<r.length;i++){ if(!findInArr(l,r[i])){ console.log(r[i]); l.push(r[i]); } } return l; } document.write(dup(arr,0,arr.length-1));
|