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
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]);
}
}