I'm going through an array that is filled with strings, but on the second "test case" my if-statement in the last for-loop stops checking my input. This means I'm getting the right output when passing in the whole input, but the second part (starting at the second single digit 3) only "fails" the for-loop if-statment check under the comment "Number of peanut specs"
const main = () => {
for (let i = 0; i < lines.length; i++) {
// NUMBER OF BOXES
if (lines[i].split(" ").length == 1 && checker) {
boxesToRead = lines[i];
checker = false;
//CHECK
// console.log("NUM: BOXES: " + boxesToRead);
// NUMBER OF BOX SPECS
} else if (lines[i].split(" ").length == 5) {
let nums = lines[i].split(" "),
x1 = nums[0],
y1 = nums[1],
x2 = nums[2],
y2 = nums[3],
size = nums[4];
boxes.push([x1, y1, x2, y2, size]);
//CHECK
// console.log("NUM: BOX SPECS");
// console.log(boxes);
// NUMBER OF PEANUTS
} else if (lines[i].split(" ").length == 1 && !checker) {
peanutStop = lines[i];
checker = true;
//CHECK
// console.log("NUM: PEANUTSTOP: " + peanutStop + " " + peanutCounter);
// console.log(boxesToRead);
// NUMBER OF PEANUT SPECS
} else if (lines[i].split(" ").length == 3) {
// SPLITS the current Peanut into nums.
let nums = lines[i].split(" "),
x = nums[0],
y = nums[1],
size = nums[2];
// TESTING
for (let i = 0; i < boxesToRead; i++) {
if (
x >= boxes[i][0] &&
y >= boxes[i][1] &&
x <= boxes[i][2] &&
y <= boxes[i][3]
) {
console.log("Something HAPPENED");
if (size == boxes[i][4]) {
console.log(size + " " + "correct");
} else {
console.log(size + " " + boxes[i][4]);
}
}
}
//CHECK
// console.log("NUM: PEANUT SPEC: ");
// console.log(nums);
//
peanutCounter++;
console.log(peanutCounter);
if (peanutCounter == peanutStop) {
console.log(" ");
peanutCounter = 0;
boxes = [];
}
}
}
};
Here's the input I'm trying to run:
2
0 0 1 1 small
3 2 6 5 large
3
2 0 small
0.5 0.6 medium
3 4 large
3
60.0 2.9 111.4 32.9 medium
20.0 82.6 43.4 153.1 small
34.7 9.6 56.6 78.2 large
6
60.0 8.3 small
43.4 153.1 small
13.4 55.9 medium
61.5 68.1 medium
72.1 69.1 large
78.4 13.2 large
0