My goal is to batch the data, using "Repair" as a separator for the data.
Splitting criteria = Repair
Copper limit = 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 attempted to iterate until the first occurrence of repair using a for loop but encountered issues.
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 overLimit = [];
let underLimit =[];
let isUnderLimit = true;
for(let i = indexTemp; i < json.length; i++){
indexTemp ++;
if(json[i].Cu > 2.5){
isUnderLimit = false;
break;
} else {
underLim.push(json[i]);
}
}
I'm struggling to understand why I can't separate the data as intended.