Hi, I’m trying to do some algorithm but no luck :/
I have one data received that I store in variable line, first field [0] contains a unique id and [1]and[2] has some value.
Sometimes data is from same id than from other id.
I need to store this data in a table [] ,if data id existes, it replaces the old value, if no data id exists, it will add it to table and the values.
The code I done is this, but seems not running correct :/
[CODE]/*
table=[ [ ‘xxxx’, ‘-40’, ‘1233’ ],
[ ‘abcd’, ‘-60’, ‘1233’ ],
[ ‘zzzz’, ‘-130’, ‘1233’ ] ];
line = [ ‘zzzz’, ‘-130’, ‘1233’ ];
i=0;
line changes first field ‘zzzz’ it’s id from the data sender on a network
could be from same point or from other with a diferent id
*/
i=0;
z=table.length;
while(i<z) {
if(table[i][0] != line[0] ) {
i++
if(i==z){
table[i] = line
i=0;
break;
}
}
else {
table[i]=line;
i=0;
break;
}
}
Any help to this code do the right task like add new id’s to table, and if data from same id it replaces the old values on table.
Any help is welcome
Regards ?