RE: Coding challenge #2 - Winners!
Thanks @armandocat.
For anyone interested in knowing how the code works, here goes:
In order to reverse a linked list, one has to loop through the entire list and change the 'next' pointer of each node to point to the previous node.
In the case of a recursive function, we "loop" through the list by reversing the current node and the calling the recursive function again on the next node. A recursive function also always need to start with a stop condition to prevent infinite loops and stack-overflows. In this case the stop condition is when the node it's given is either null or has no next node.
In the case of an iterative function. We loop through the list with well... a loop. A while loop in this case where we check that the current node we're reversing isn't null.
That's it. Simple really... if you have the solution in front of you 😝.
Can't wait for the next one.