JSFiddle - React, Tailwind, and code Playground

by nithyanandam venu

JavaScript

let constructTree = (treeconfig,childCount,nodeLimit,nodeCount) => {
      for(let i=0;i<childCount;i++){
      		nodeCount++;
          treeconfig.children.push({'title':'name','children':[]});
      }
      
      if((nodeLimit / 2) >  nodeCount ){
       		treeconfig.children.map((item) => {
        		constructTree(item,2,10,nodeCount)
      		});   
      }
      
      return treeconfig; 
           
}

console.log(constructTree({'title':'parent','children':[]},2,10,0));