7 Replies Latest reply on Aug 10, 2010 7:37 PM by kglad

# comparing Array

Hello,

can you plz help me.
i am checking two array.

var temItemNo_array:Array = Array(12,13,17,19,20);
var Item_array:Array = Array(12, 13, 14, 15, 16, 17);

when checked [B]temItemNo[/B] &&  [B]Item_array[/B] in this arrays 12,13 are same no.
but when 12 & 13 got continuous common no. that time want stop on 13 no and add on 13+1=14

Thanks
JaxNa

what?

• ###### 2. Re: comparing Array

here are my two array.

when i compare this array that time i got common no.(12,13,17).

12 and 13 is continuous no.
when compare array and i got 12, 13 that time it should be stop this compare and that time i want  next no that is (14)

var temItemNo_array:Array = Array(12,13,17,19,20);
var Item_array:Array = Array(12, 13, 14, 15, 16, 17);

• ###### 3. Re: comparing Array

ok.  i understand you're looking for common elements in 2 arrays.  i understand you want to check if any common elements are adjacent integers.

if there are 2 common elements that are adjacent integers you want to search for the smallest integer greater than the 2 adjacent ones?  does that search have anything to do with elements in either array?

• ###### 4. Re: comparing Array

if there are 2 common elements that are adjacent integers then i want next integer

if 12 & 13 are 2 common element that are adjacent then i want next integer is 14.

one more example

if 17& 18 then i want  next integer is 19.

Thanks a lot kglad

• ###### 5. Re: comparing Array

if both arrays contain integers you can use the following function to return an array that meets your criteria:

var returnA:Array = [];
var t1:Array = a1.slice();
var t2:Array = a2.slice();
t1.sort(18).reverse();
t2.sort(18).reverse();
for(var i=0;i<t1.length;i++){
for(var j=0;j<t2.length;j++){
if(t1[i]==t2[j]){
if(t1[i+1]==t1[i]+1 && t1[i+1]==t2[j+1]){
returnA.push(t1[i]+2);
}
}
}
}
return returnA;
}

• ###### 6. Re: comparing Array

hey thanks a lot

can you give me one more ans plz??

var temItemNo_array:Array = Array(11,14,15,19,20);
var Item_array:Array = Array(12, 13, 14, 15, 16, 17);

temItemNo_array in this array first integer is not common so that loop should be the break.

how can do this?

Thank dear

• ###### 7. Re: comparing Array

with your criteria to search for adjacent integers common to both arrays, passing both those arrays to the function i suggested should return 16.