Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. LinkedList.prototype.append = function(data) {
  2. let newNode = new Node(data);
  3. let nodeToCheck = this.head;
  4. if(!nodeToCheck) {
  5. this.head = newNode;
  6.  
  7. // increment the LinkedList's length
  8. this.length++;
  9. return newNode;
  10. } else {
  11. while(nodeToCheck.next) {
  12. nodeToCheck = nodeToCheck.next;
  13. }
  14.  
  15. // once were at the end of the list
  16. nodeToCheck.next = newNode;
  17.  
  18. // increment the LinkedList's length
  19. this.length++;
  20. return newNode;
  21. }
  22. }
Add Comment
Please, Sign In to add comment