node-linkedlist
node-linkedlist copied to clipboard
Problem when removing first element of the list
Hey guys, I think I've observed incorrect behavior when removing the first element from the list:
I simply create the list with the strings 0, 1, 2, 3
var LinkedList = require('linkedlist')
var list = new LinkedList()
for (var i = 0; i < 4; i++) list.push(i.toString());
Now I iterate through the list and demonstrate that removing an element that isn't first works fine console.log("\nExpect 0, 1, 2, 3");
while (list.next()) {
console.log(list.current)
if (list.current === "1") list.removeCurrent();
}
We see the following output 0, 1, 2, 3 and expect that the list now contains the strings 0, 2, 3
If we now iterate through the list again but this time remove the first element we get something unexpected:
list.resetCursor();
while (list.next()) {
console.log(list.current)
if (list.current === "0") list.removeCurrent();
}
Here we see 0, 3 but we expected 0, 2, 3
@siggiorn thanks for reporting this, I am off duty for the next 3 weeks but I will try to look into this ASAP. If you want / can please submit a PR with a failing test suite, that would be super helpful
@kilianc no problem, just created that PR