JSFiddle - React, Tailwind, and code Playground

by ifandelse

JavaScript

var LinkedNode = function(item, prev, next) {
  this.item = item;
  this.prev = prev;
  this.next = next;
};

var LinkedList = function(item) {
  this.head = item ? new LinkedNode(item, null, null) : null;
  this.last = this.head;
  this.length = 0;
  this.current;
};

LinkedList.prototype.add = function( item ) {
  var node;
  if( this.head === null ) {
    node = this.head = new LinkedNode(item, null, null);
  } else {
    node = this.last.next = new LinkedNode(item, this.last, null);
  }
  this.length += 1;
  this.last = node;
};
  

var list = new LinkedList();
var i = 100
while(i > 0) {
  list.add(i--);
}

for(var x = list.head; x; x = x.next) {
  $('body').append("<div>" + x.item + "</div>");
  //console.log(x.item);
}

//$('body').html("<div><pre>" + JSON.stringify(list, null, 2) + "</pre></div>");
console.log(list);