It works because of the line immediately preceding that line:
this.sizes[stackNumber]++;
That seems tricky β difficult to come back to later on and immediately understand how those lines work in concert. Perhaps it would be more straight-forward to swap those two lines and add 1 to the indexOfTop instead:
// insert our new value to the top of the stackthis.values[this.indexOfTop(stackNumber)+1]=value;// increment our stack size by 1this.sizes[stackNumber]++;
Oh. I see it now π€¦π»ββοΈ!
It works because of the line immediately preceding that line:
That seems tricky β difficult to come back to later on and immediately understand how those lines work in concert. Perhaps it would be more straight-forward to swap those two lines and add 1 to the
indexOfTop
instead:It is a bit convoluted eh?
Yeah, maybe a little. Not too bad. Once I actually ran the code, I began to understand the cleverness at work.