(element)
| 119 | |
| 120 | // Removes the node with the value as param |
| 121 | remove(element) { |
| 122 | if (this.isEmpty()) return null |
| 123 | let { currentNode } = this.initiateNodeAndIndex() |
| 124 | let removedNode = null |
| 125 | // Check if the head node is the element to remove |
| 126 | if (currentNode.data === element) { |
| 127 | return this.removeFirst() |
| 128 | } |
| 129 | // Check if the tail node is the element to remove |
| 130 | if (this.tailNode.data === element) { |
| 131 | return this.removeLast() |
| 132 | } |
| 133 | // Check which node is the node to remove |
| 134 | while (currentNode.next) { |
| 135 | if (currentNode.next.data === element) { |
| 136 | removedNode = currentNode.next |
| 137 | currentNode.next = currentNode.next.next |
| 138 | this.length-- |
| 139 | return removedNode.data |
| 140 | } |
| 141 | currentNode = currentNode.next |
| 142 | } |
| 143 | return removedNode?.data || null |
| 144 | } |
| 145 | |
| 146 | // Returns the index of the element passed as param otherwise -1 |
| 147 | indexOf(element) { |
no test coverage detected