I've trimmed the code down to what I think is relevant. This function is run once at the start of the $(document).ready function.
var evenGaps = [];
const NUMBERED_NEIGHBORS = //some array
var evenLocations = //some array
var gapNumber = 0;
function gapFinder() {
for (var x = 0; x < NUMBERED_NEIGHBORS[evenLocations[i + 2]][1].length; x++) {
if (NUMBERED_NEIGHBORS[evenLocations[i]][1][p] ===
NUMBERED_NEIGHBORS[evenLocations[i + 2]][1][x]) {
var delta0 = evenGaps[gapNumber]["1_Gap"][0] - evenGaps[gapNumber]["2_Filler"][0];
var delta1 = evenGaps[gapNumber]["1_Gap"][1] - evenGaps[gapNumber]["2_Filler"][1];
var delta = [delta0, delta1];
evenGaps.push([]);
evenGaps[gapNumber]["5_Distance"] = Math.max(Math.abs(delta[0]),
Math.abs(delta[1]));
if (Math.abs(delta[0]) === Math.abs(delta[1])) {
evenGaps[gapNumber]["6_Single Path?"] = true;
} else {
evenGaps[gapNumber]["6_Single Path?"] = false;
};
if (evenGaps[gapNumber]["6_Single Path?"] &&
evenGaps[gapNumber]["5_Distance"] >= 2) {
//THE ISSUE ARISES WHEN THE LINE BELOW IS ADDED
for (var i = 0; i < evenGaps[gapNumber]["5_Distance"]; i++) {}
}
gapNumber++;
}
}
}
I'm able to run the code without issue in Chrome when it doesn't include that last for() loop. Even if I run it as an empty loop, an infinite loop still occurs, however, it's the outer loop that's refusing to break (I know this because I have information printint to the console that's above the inner loop). This generally only occurs when I reload the page quickly. If I remove that one line of code, I can reload it as quickly and as many times as I want without issue. When I try running it in Firefox, it appears to also go into the loop but Firefox stops it with the stop script dialog box, however it shows the bad script as the for() loop that I'm saying is causing the issue.
Also, I'm using a very simple Node.js server.
ivariable in theNUMBERED_NEIGHBORS[evenLocations[i + 2]][1].lengthexpression come from?