canaille

02-09-2007, 01:40 PM

Hi ,

I would like to dynamically populate tables

var bloc = new Array();which contain nested arrays(with constant size)

bloc[0]= new array(10);

bloc[1]= new array(10);

// till bloc[k]

The T table containing my values are constitued from inner array with different lengths

var T= new Array();

T[0], T[1], T[2],till T[n]

I start to fill the bloc[0] with T[0] and if the length of T[0] is smaller than 10 I go on with T[1]

But I have the constraint to have unique element per bloc

I have already checked than the individual table T[0], T[1], T[n]...have unique elements

for exemple

T[0]= ['1','2','3','4','5','6','20'];

T[1]= ['30','20','10','11'];

then bloc[0]should be['1','2','3','4','5','6','20','30','10','11']

function Test(){

var k = 0; //counter of block

var j=0;// loop in block

var n=0; //counter of nested T

var i=0;// loop in T[]

var found;

bloc[0][0]=T[0][0]; //initialisation: the first element in the first bloc come from the first

elemt of T[0]

for (i=0; i<(T[n].length);i++){ //i is the counter of element in T[]

if(i%10==0)k++; //if already 10 elements in the block then a new bloc created

if (bloc[k][j] == T[n][i]) {

si element found do nothing

found = true;

//break;

}

if (!found){

bloc[k][bloc[k].length] = T[n][i];

// then put it in the block

}

j++;

}

n++;

alert(bloc);

}

The function didnot work

Problem with loop?

many thanks for your ideas

I would like to dynamically populate tables

var bloc = new Array();which contain nested arrays(with constant size)

bloc[0]= new array(10);

bloc[1]= new array(10);

// till bloc[k]

The T table containing my values are constitued from inner array with different lengths

var T= new Array();

T[0], T[1], T[2],till T[n]

I start to fill the bloc[0] with T[0] and if the length of T[0] is smaller than 10 I go on with T[1]

But I have the constraint to have unique element per bloc

I have already checked than the individual table T[0], T[1], T[n]...have unique elements

for exemple

T[0]= ['1','2','3','4','5','6','20'];

T[1]= ['30','20','10','11'];

then bloc[0]should be['1','2','3','4','5','6','20','30','10','11']

function Test(){

var k = 0; //counter of block

var j=0;// loop in block

var n=0; //counter of nested T

var i=0;// loop in T[]

var found;

bloc[0][0]=T[0][0]; //initialisation: the first element in the first bloc come from the first

elemt of T[0]

for (i=0; i<(T[n].length);i++){ //i is the counter of element in T[]

if(i%10==0)k++; //if already 10 elements in the block then a new bloc created

if (bloc[k][j] == T[n][i]) {

si element found do nothing

found = true;

//break;

}

if (!found){

bloc[k][bloc[k].length] = T[n][i];

// then put it in the block

}

j++;

}

n++;

alert(bloc);

}

The function didnot work

Problem with loop?

many thanks for your ideas