function findDuplicate(arr){
var arr1=[]; //for processing array
var arr2=[]; // for storing result
var c1; // for arr1
var c2=0; // for arr2
var dupli;
var length=arr.length;
while(length>0){
c1=0;
dupli=false;
arr1=[];
for(var j=1;j<length;j++){
if(arr[0]!=arr[j]){
arr1[c1]=arr[j];
c1++;
}
else{
if(!dupli){
arr2[c2]=arr[j];
c2++;
dupli=true;
}
}
}
arr=arr1;
length=arr.length;
}
return arr2;
}
alert('Result is : ' + findDuplicate([1,2,3,4,5]));
var arr1=[]; //for processing array
var arr2=[]; // for storing result
var c1; // for arr1
var c2=0; // for arr2
var dupli;
var length=arr.length;
while(length>0){
c1=0;
dupli=false;
arr1=[];
for(var j=1;j<length;j++){
if(arr[0]!=arr[j]){
arr1[c1]=arr[j];
c1++;
}
else{
if(!dupli){
arr2[c2]=arr[j];
c2++;
dupli=true;
}
}
}
arr=arr1;
length=arr.length;
}
return arr2;
}
alert('Result is : ' + findDuplicate([1,2,3,4,5]));
No comments:
Post a Comment