JSFiddle - React, Tailwind, and code Playground

by CommandLineDesign

JavaScript

function Node(data) {
  this.data = data;
  this.next = null;
}

function push(head, data) {
    var result = {};
	if(!head){
    	result = new Node(data);
    } else {
        if(!head.next){
            result.next = new Node(head.data);
            result.data = data;
        } else {
            result.next = head
            result.data = data;		
        }
    }
  return result;
}


function buildOneTwoThree() {
  return push(push(push(null, 3), 2), 1);
}

//console.log(push(push(null, 3), 2));

console.log(buildOneTwoThree().next.next.data);