Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Data-Structures/Linked-List/SinglyLinkedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Data-Structures/Linked-List/test/SinglyLinkedList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down