Skip to content

Commit 1666c3a

Browse files
authored
fix error in SinglyLinkedList head method (#1322)
* fix error in SinglyLinkedList head method * test: update check head test for SinglyLinkedList * fix: code style error * fix: remove extra semicolons --------- Co-authored-by: Bekzod <[email protected]>
1 parent 331a4d2 commit 1666c3a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: Data-Structures/Linked-List/SinglyLinkedList.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ 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
4747
tail () {
48-
return this.tailNode?.data || null
48+
return this.tailNode?.data ?? null
4949
}
5050

5151
// Return if the list is empty

Diff for: Data-Structures/Linked-List/test/SinglyLinkedList.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ describe('SinglyLinkedList', () => {
148148

149149
list.addFirst(30)
150150
expect(list.head()).toBe(30)
151+
152+
// check for a falsy head data
153+
list.addFirst(false)
154+
expect(list.head()).toBe(false)
151155
})
152156

153157
it('Check tail', () => {
@@ -162,6 +166,10 @@ describe('SinglyLinkedList', () => {
162166

163167
list.addFirst(30)
164168
expect(list.tail()).toBe(20)
169+
170+
// check for a falsy tail data
171+
list.addLast(false)
172+
expect(list.tail()).toBe(false)
165173
})
166174

167175
it('Check size', () => {

0 commit comments

Comments
 (0)