Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
How can I check an array of arrays to see if an internal array has both values greater than the values of the previous one?

I have come to this code, but it results in an error. The idea is to have, at the end of the program, an array of arrays with all the original arrays that meet the condition of having both values greater than the values of the previous array.

var data = [[68, 150], [70, 155], [55, 160]];
var result = [];

for(i=0; i<data.length; i++){
    
    var firstPosterior = data[i+1][0];
    var lastPosterior = data[i+1][1];
    var firstAnterior = data[i][0];
    var lastAnterior = data[i][1];
    
    if(
        firstPosterior > firstAnterior &&
        lastPosterior > lastAnterior
        ) {
        result.push(firstPosterior, firstPosterior);
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First you have a compilation error at

for(i=0; i<data.length; i++) // i is not defined. You should use let, var to declare it

Here it is an example


var data = [[68, 150], [70, 155], [55, 160]];
var result = [];

for(let i=0; i<data.length -1; i++){
    
    var firstPosterior = data[i+1][0];
    var lastPosterior = data[i+1][1];
    var firstAnterior = data[i][0];
    var lastAnterior = data[i][1];
    
    if(
        firstPosterior > firstAnterior &&
        lastPosterior > lastAnterior
        ) {
        result.push(data[i+1]);
    }
}

I am adding in the result only arrays that met the condition.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda