Reverse Linked List

Linked list construction is covered here

Example:

Linked list: [1,2,3,4,5]
Output: [5,4,3,2,1]
Linked List: []
Output: []

Solution:

var reverse = function (head) {
  var prev = null
  while (head != null) {
    var temp = head.next
    head.next = prev
    prev = head
    head = temp
  }
  return prev
}
“If you only read the books that everyone else is reading, you can only think what everyone else is thinking.” - Murakami