xxxxxxxxxx
insertLastNode(data) {
const newNode = new NewNode(data);
if (!this.head) {
this.head = newNode;
} else {
let currentNode = this.head;
while (currentNode.next) {
currentNode = currentNode.next;
}
currentNode.next = newNode;
}
this.tail=newNode;
this.length++;
}
//if you find the answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)