Function to reverse the linked list
function reverse ( head ) { var prev = null , current = head , next = null ; while ( current != null ) { next = current . next ; current . next = prev ; prev = current ; current = next ; } return prev ; }