me and my partner have an issue. in the addToTail method we end by reassigning veryEndResult to newNode (veryEndResult = newNode).
What we were actually trying to do is reassign the value of veryEndResult (this.head.next) to newNode, is there a way to do this? We couldn't google it either because we don't really know how to go about forming that question.
Would love if an experienced coder could help us out on this.
class LinkedList {
constructor () {
this.head = null;
this.length = 0;
}
addToHead (data) {
const newNode = new LinkedListNode(data, this.head);
this.head = newNode;
this.length ++;
return true;
}
addToTail (data) {
const newNode = new LinkedListNode(data, null);
let test = ['this','head'];
this.length ++;
for (let i = 0 ; i < this.length - 1 ; i++) {
test.push('next');
}
let endResult = test.join('.');
let veryEndResult = eval(endResult);
console.log(endResult);
veryEndResult = newNode;
}
}
class LinkedListNode {
constructor (value, next) {
this.value = value;
this.next = next;
}
}
let linkedList = new LinkedList();
linkedList.addToHead(20);
linkedList.addToTail(30);