Reverse a linked list

  • + 0 comments

    js

    function reverse(llist) {
      let prev = null
      let current = llist
      let next = null
      
      while(current !== null) {
          next = current.next
          current.next = prev
          prev = current
          current = next
      }
    llist = prev
    return llist
    }