kilianc / kilianc/node-linkedlist

Problem when removing first element of the list

Open
#1 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
28
Forks
11
PR merge metrics
No merged PRs in 30d

Description

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`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the behavior with the LinkedList example using push, next, removeCurrent, and resetCursor. Trace removal of the first element after removing "1" and verify the list still iterates as 0, 2, 3 after the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.