Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1666c3a

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 parent331a4d2 commit1666c3a

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-
returnthis.headNode?.data||null
43+
returnthis.headNode?.data??null
4444
}
4545

4646
// Returns the tail
4747
tail(){
48-
returnthis.tailNode?.data||null
48+
returnthis.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)

[8]ページ先頭

©2009-2025 Movatter.jp