Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda