Hacker News new | ask | show | jobs
by Rockdtben 4868 days ago
Never wrote javascript before.

http://jsbin.com/ugojoq/267/edit

LinkedList.prototype.reverse = function () {

  var start = this.head;
  var prev = this.head;
  var curr = prev.next;
  prev.next = null;
  while(curr !== null) {
    var next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  this.head = prev;
};