Skip to content

fix bug and add test for deleting last node in a linked list#37

Open
patrick-plue wants to merge 2 commits intobtholt:mainfrom
patrick-plue:bugfix/linkedlist
Open

fix bug and add test for deleting last node in a linked list#37
patrick-plue wants to merge 2 commits intobtholt:mainfrom
patrick-plue:bugfix/linkedlist

Conversation

@patrick-plue
Copy link

When trying to delete the last node in a linked list, a type error occurred.
`TypeError: Cannot read properties of null (reading 'next')

  89 |         if (!excise) return null;
  90 |         node.next = excise.next;
> 91 |         if (!node.next.next) this.tail = node.next;
     |                        ^
  92 |         this.length--;
  93 |         return excise.value;
  94 |     }

  at LinkedList.delete (specs/arrays/linkedlist.solution.test.js:91:24)
  at Object.<anonymous> (specs/arrays/linkedlist.solution.test.js:173:9)`

I fixed this and added a test case for deleting the last node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant