Skip to content

Instantly share code, notes, and snippets.

@GAierken
Last active November 20, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GAierken/c8a55e24b95cb80654145e14f799790d to your computer and use it in GitHub Desktop.
Save GAierken/c8a55e24b95cb80654145e14f799790d to your computer and use it in GitHub Desktop.
const reverseList = (head) => {
//initiate previous as null
let previous = null
//initiate next without assigning
let next
//keep iteration while head is not null
while(head){
//store the current node's next node
next = head.next
//reassign head's next with previous node
head.next = previous
//reassign previous with reversed current node
previous = head
//reassign head with next node
head = next
}
//after reversing return previous list
return previous
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment