mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
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 <bekzodisakov18@gmail.com>
This commit is contained in:
@ -40,12 +40,12 @@ class LinkedList {
|
||||
|
||||
// Returns the head
|
||||
head () {
|
||||
return this.headNode?.data || null
|
||||
return this.headNode?.data ?? null
|
||||
}
|
||||
|
||||
// Returns the tail
|
||||
tail () {
|
||||
return this.tailNode?.data || null
|
||||
return this.tailNode?.data ?? null
|
||||
}
|
||||
|
||||
// Return if the list is empty
|
||||
|
@ -148,6 +148,10 @@ describe('SinglyLinkedList', () => {
|
||||
|
||||
list.addFirst(30)
|
||||
expect(list.head()).toBe(30)
|
||||
|
||||
// check for a falsy head data
|
||||
list.addFirst(false)
|
||||
expect(list.head()).toBe(false)
|
||||
})
|
||||
|
||||
it('Check tail', () => {
|
||||
@ -162,6 +166,10 @@ describe('SinglyLinkedList', () => {
|
||||
|
||||
list.addFirst(30)
|
||||
expect(list.tail()).toBe(20)
|
||||
|
||||
// check for a falsy tail data
|
||||
list.addLast(false)
|
||||
expect(list.tail()).toBe(false)
|
||||
})
|
||||
|
||||
it('Check size', () => {
|
||||
|
Reference in New Issue
Block a user