Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!