(index, element)
| 172 | |
| 173 | // Adds the element at specified index |
| 174 | addAt(index, element) { |
| 175 | // Check if index is out of bounds of list |
| 176 | if (index > this.length || index < 0) { |
| 177 | throw new RangeError('Out of Range index') |
| 178 | } |
| 179 | if (index === 0) return this.addFirst(element) |
| 180 | if (index === this.length) return this.addLast(element) |
| 181 | let { currentIndex, currentNode } = this.initiateNodeAndIndex() |
| 182 | const node = new Node(element) |
| 183 | |
| 184 | while (currentIndex !== index - 1) { |
| 185 | currentIndex++ |
| 186 | currentNode = currentNode.next |
| 187 | } |
| 188 | |
| 189 | // Adding the node at specified index |
| 190 | const tempNode = currentNode.next |
| 191 | currentNode.next = node |
| 192 | node.next = tempNode |
| 193 | // Incrementing the length |
| 194 | this.length++ |
| 195 | return this.size() |
| 196 | } |
| 197 | |
| 198 | // Removes the node at specified index |
| 199 | removeAt(index) { |
no test coverage detected