Skip to content

Commit 7be303f

Browse files
committed
fix error in SinglyLinkedList head method
1 parent 331a4d2 commit 7be303f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Data-Structures/Linked-List/SinglyLinkedList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LinkedList {
4040

4141
// Returns the head
4242
head () {
43-
return this.headNode?.data || null
43+
return this.headNode?.data ?? null
4444
}
4545

4646
// Returns the tail

Data-Structures/Linked-List/test/SinglyLinkedList.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ describe('SinglyLinkedList', () => {
148148

149149
list.addFirst(30)
150150
expect(list.head()).toBe(30)
151+
152+
list.addFirst(0)
153+
expect(list.head()).toBe(0)
151154
})
152155

153156
it('Check tail', () => {

0 commit comments

Comments
 (0)