JSFiddle - React, Tailwind, and code Playground

by ning wang

HTML

<div id='output'>
</div>

JavaScript

function Tree(left,base,right){
	this.left = left;
  this.base = base;
  this.right = right;
}

function*inorder(t){
	if(t){
  	yield*inorder(t.left);
    yield t.base;
    yield*inorder(t.right);
  }
}

function make(array){
	if(array.length == 1){
  	return new Tree(null,array[0],null);
  }
  return new Tree(make(array[0]),array[1],make(array[2]));
}

var tree = make([[['a'],'b',['c']],'d',[['e'],'f',['g']]]);
var result = [];
for(let node of inorder(tree)){
	result.push(node);
}

var ele = document.getElementById('output');
ele.innerHTML = result;