title: Remove elements from singly linked list (javascript)
body: <p>I'm doing a CodeFights problem, trying to remove elements from a singly linked list that has the value k.</p>
  
  <p>Below is what I have (l is the list and k is the value):</p>
  
  <pre><code>function removeKFromList(l, k) {
      //figure out the head of the new list so we can reference it later
      var head = l;
  
      while (head.value === k){
          head = head.next;
      }
  
      var node = head;
      var temp = null;
  
      while (node &amp;&amp; node !== null) {
          if (node.next.value === k){
              temp = node.next.next;
              node.next.next = null;
              node.next = temp;
          }
          node = node.next; 
          console.log("+++", head)
      }
  
      console.log("---", head)  
  }
  </code></pre>
  
  <p>The CodeFight test cast is 3 -> 1 -> 2 -> 3 -> 4 -> 5. The final result would have been 1 -> 2 -> 4 -> 5. But my '---' console log keeps returning "Empty" (according to the CodeFights console). </p>
  
  <p>My '+++' console log returns the correct head with element each loop. </p>
  
  <p>I've been pulling my hair out over this, any idea what is missing here? </p>