JS Push stripping last elements of pushed arrays


#1

So while trying to code a solution for Criss Cross, I’m coming across a bug that’s preventing me from implementing my solution. Here is an example of what’s happening with the debug output beside:

this.debug("current path is: " + curPath); // current path is: 0,0,0,0,0,0,1
this.debug("the length of that path is: " + curPath.length); // the length of that path is 7
this.paths.push(curPath);
this.debug("the added path is: " + this.paths[this.paths.length-1]); // the added path is: 0,0,0,0,0,0
this.debug("the length of the path when added is: " + this.paths[this.paths.length-1].length); // the length of the path when added is 6

Where curPath is an array of length 7 with numerical values and this.paths is an array containing several paths of length 7 (or should be 7 anyways).

It would seem as though when I push my current path here, the value it has in this.paths is different from the value it had when I pushed it. As you can see, I printed it out as it was before I added it and then printed it out in the structure I added it to, and it was different. This happens for any value of curPath, as this.paths always contained paths of size 7 instead of 7, even though my debugging showed curPath was always length 7 when I pushed it.

Any ideas? I can’t play the game while this bug exists because I can’t implement my solution.

EDIT:

After some further testing I’m yielding this:

if(curPath.length === 7) {
    this.debug(curPath); // [0, 0, 0, 0, 0, 0]
    this.debug(""+curPath); // 0,0,0,0,0,0,1       
}

I expect it to be the output from the the second debug statement and not the first, since I’ve explicitly stated it has to be of length 7. When I tested with just a fresh array, it worked perfectly fine, and the two outputs matched.

Is it possible there’s just a problem with the debugger?

I currently have a workaround as follows, but I’m really not a fan of it by any stretch of the imagination.

this.paths.push(curPath);
this.paths[this.paths.length - 1].push(curPath[curPath.length - 1]);

If you could look into it that’d be great.


#2

Thanks for the great bug report. I’m tracking the bug over here. Seems like a similar thing with API protection that I’ve run into in the past. I should be able to figure this out when I next get ambitious to dive into the heart of the transpiler.