Skip to content

Instantly share code, notes, and snippets.

@claytonjwong
Created December 22, 2021 15:26
Show Gist options
  • Select an option

  • Save claytonjwong/f9c32feb3fafa2f8a4a1bc23b72f8708 to your computer and use it in GitHub Desktop.

Select an option

Save claytonjwong/f9c32feb3fafa2f8a4a1bc23b72f8708 to your computer and use it in GitHub Desktop.

Revisions

  1. claytonjwong created this gist Dec 22, 2021.
    14 changes: 14 additions & 0 deletions rev_linked_list.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    //
    // Recursively change each node of the linked list such that next
    // is the last node seen during a linear scan of the linked list.
    //
    let reverseList = head => {
    let go = (node = head, last = null) => {
    let next = node.next;
    node.next = last;
    if (!next)
    return node;
    return go(next, node);
    };
    return head ? go() : null;
    };