Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LinkedList.prototype.append = function(data) {
- let newNode = new Node(data);
- let nodeToCheck = this.head;
- if(!nodeToCheck) {
- this.head = newNode;
- // increment the LinkedList's length
- this.length++;
- return newNode;
- } else {
- while(nodeToCheck.next) {
- nodeToCheck = nodeToCheck.next;
- }
- // once were at the end of the list
- nodeToCheck.next = newNode;
- // increment the LinkedList's length
- this.length++;
- return newNode;
- }
- }
Add Comment
Please, Sign In to add comment