I made a Javascript function to reverse a linked list. But the code seems to produce an infinite loop. Please help me figure out the bug.
reverse()
{
var current=this.head;
var prevNext=current.next;
this.tail.next=null;
this.tail=current;
while(current.next!==null)
{
var temp=prevNext;
if(temp.next!==null)
prevNext=temp.next;
temp.next=current;
current=temp;
}
this.head=current;
}