title: strategies to reverse a linked list in JavaScript
body: <p>I just struggled through a simple interview question: Please reverse a singly linked list.</p>
  
  <p>While I failed to provide a working answer in time to save the interview, I was able to come up with a solution afterwards.</p>
  
  <p>Is my solution correct? How would you analyze this with Big-Oh? Are there more efficient ways to reverse a singly linked list?</p>
  
  <pre><code>// reverse a linked list
  
  var reverseLinkedList = function(linkedlist) {
    var node = linkedlist;
    var previous = null;
  
    while(node) {
      // reverse pointer
      node.next = previous;
      // increment previous to current node
      previous = node;
      // increment node to next node
      if (node.next){
        node = node.next
      } else {
        node = null;
      }
    }
  }
  </code></pre>
  
  <p>Note: In my search for similar posts, I did find <a href="https://stackoverflow.com/questions/11840506/javascript-link-list-reference">one example</a> in JavaScript. I was wondering if my code is possible (without a <code>temp</code> variable). Thank you.</p>