JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

(() => {

  function LinkNode(val) {
    this.val = val;
    this.next = null;
  }

  LinkNode.prototype.setNext = function(node) {
    this.next = node;
    return this;
  }

  let arr = [7, 10, 13];

  function toLinked(array) {
    if (!array.length) {
      return null;
    }
    
    return new LinkNode(array[0])
    	.setNext(toLinked(array.slice(1)))
  }

  console.log(toLinked(arr));
})();