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:
BekzodIsakov
2023-05-15 13:05:09 +05:00
committed by GitHub
parent 331a4d26cf
commit 1666c3a0be
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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', () => {