Last active
November 20, 2020 02:08
-
-
Save GAierken/c8a55e24b95cb80654145e14f799790d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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