I'm doing a code to try to convert some data into a table.
Specifically, I have the data in 3 arrays with the following form:
- Survey [ age ,
name_of_periodico ] - Interval
[ First_number_of_interval (the number
minor),
Second_numero_del_intervalo (the largest number)] - Newspapers [ name_of_periodico ]
I need to obtain the positions that occupy the values of the array surveys with respect to the other two arrays trying to make it efficient. Here's an example:
[21, "el_pais"] --- > [3,0]
Since 21 would be included in the 4 interval [17,25] and 0 because it is the first newspaper ["el_pais"].
Well, at first I go through the array of surveys and for each survey I compare its positions in the array of intervals and newspapers, but it is impossible for me not to do so for all surveys.
Any ideas? Thank you very much.
var valores_encuesta = [[11, "el_pais"],[21,"el_pais"],[31,"el_mundo"],[42, "abc"],[45,"el_pais"],[46, "el_pais"],[50, "abc"],[51, "el_mundo"],[52,"el_mundo"],[70,"abc"],];
var intervalos = [[1, 5],[6, 10],[11, 16],[17, 25],[26, 31],[32, 46],[47, 54],[55, 65],[66, 80],[81, 99],];
var periodicos = ["el_pais","el_mundo","abc"];
var x=0;
var y=0;
// Recorro el array con las encuestas para compararlos con los intervalos y los periodicos
for (i=0 ;i<valores_encuesta.length-1;i++){
console.log("------------------------------------------------------------------");
//Recorro el array de los intervalos y me quedo con que posicion ocupa X
while (x<intervalos.length-1 &&
!(intervalos[x][0]>=valores_encuesta[i][0]
&& valores_encuesta[i][0]<=intervalos[x][1])){
console.log("Encuesta: "+i+" Longitud :"+x+"Comparando "+intervalos[x][0]+">="+valores_encuesta[i][0]+"<="+intervalos[x][1]);
x++;
}
//Recorro el array de los periodicos y me quedo con la posicion y
while (y<periodicos.length-1 &&
valores_encuesta[i][1].localeCompare(periodicos[y])!=0
){//Recorro el array de los periodicos y me quedo con la posicion y
y++;
}
console.log("Encuesta "+i+" con x["+x+"] y ["+y+"]");
x=0;
y=0;
}