title: Reverse a linked list... what is wrong with my implementation?
body: <p>I'm having trouble reversing a linked list based on my implementation below. Is there something wrong or missing that I'm doing here?</p>
  
  <pre><code>class Node {
      constructor(val) {
          this.val = val;
          this.next = null;
      }
  }
  
  class SinglyLinkedList {
      constructor() {
          this.head = null;
          this.length = 0;
      }
  
      push(val) {
          var newNode = new Node(val);
  
          var current = this.head; 
  
          if (!this.head) 
              this.head = newNode; 
          else {
  
              // iterate to the end of the 
              // list 
              while (current.next) { 
                  current = current.next; 
              } 
  
              // add node 
              current.next = newNode; 
          } 
          this.length++;
  
          return this; 
      }
  
      // reverse the list
      reverse() {
          var prev = null;
          var curr = this.head;
          while (curr !== null) {
              var temp = curr.next;
              curr.next = prev;
              prev = curr;
              curr = temp;
          }
  
          return this;
      }
  
      print() {
          var arr = []
          var current = this.head;
  
          while(current) {
              arr.push(current.val);
              current = current.next; 
          }
  
          console.log(arr);
      }
  }
  </code></pre>
  
  <p>Here's my implementation when I create the object and push some nodes</p>
  
  <pre><code>var list = new SinglyLinkedList();
  list.push(1);
  list.push(2);
  list.push(3);
  list.push(4);
  </code></pre>
  
  <p>Every time I ran <code>list.reverse()</code> then <code>list.print()</code> it only prints <code>[1]</code> only and not <code>[4,3,2,1]</code>.</p>