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

165
Views
Failure of pushing batch data using a keyword and if statement

Im trying to seperate the data to batches, using the repair as a seperator for the data.
Dividing keyword = Repair
Limit of Cu = 2.5

[
  {"engineSN":"20","timeRun":"30","Cu":"2"},
  {"engineSN":"20","timeRun":"40","Cu":"2.01"},
  {"engineSN":"20","timeRun":"59","Cu":"2.5", "Decision":"Repair"},
  {"engineSN":"20","timeRun":"74","Cu":"5.4"},
  {"engineSN":"20","timeRun":"90","Cu":"3.4", "Decision":"Repair"},
  {"engineSN":"20","timeRun":"130","Cu":"5.6"},
  {"engineSN":"20","timeRun":"1800","Cu":"10.3"},
]

I have tried running until the first index of repair using a for loop but nothing works out

Code:

let json = require("json.json");
let indexOfRepair = [];
let indexTemp = 0;
for(let i = 0; i < json.length; i++){
     if(json[i].Decision == 'repair'){
         indexOfRepair.push(i);
       }
}

let overLim = [];
let underLim =[];
let isUnderLim = true;

for(let i = indexTemp; i < json.length; i++){
    indexTemp ++;
    if(json[i].Cu > 2.5){
        isUnderLim = false;
        break;
        } else {
           underLim.push(json[i]);
           }
}

I cant understand why the seperation of data wont work for me

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That is because you use the "break" keyword.

It'll end the "for loop". You should use "continue" to do next without ending the "for loop".

let json = require("json.json");
let indexOfRepair = [];
let indexTemp = 0;
for (let i = 0; i < json.length; i++) {
    if (json[i].Decision == 'repair') {
        indexOfRepair.push(i);
    }
}

let overLim = [];
let underLim = [];
let isUnderLim = true;

for (let i = indexTemp; i < json.length; i++) {
    indexTemp++;
    if (json[i].Cu > 2.5) {
        isUnderLim = false;
        break; // replace with continue
    } else {
        underLim.push(json[i]);
    }
}
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!