Skip to content

Commit 1666c3a

Browse files
authored
fix error in SinglyLinkedList head method (TheAlgorithms#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 <bekzodisakov18@gmail.com>
1 parent 331a4d2 commit 1666c3a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Data-Structures/Linked-List/SinglyLinkedList.js

Lines changed: 2 additions & 2 deletions
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

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

Lines changed: 8 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy