const input1 = "FDXEAG";
const input2 = "XDEFAG";
const dlr = input1.split('');
const ldr = input2.split('');
function createNode(dlr, ldr){
if( dlr.length === 0){
return null;
}
if(ldr.length === 0){
return null;
}
const val = dlr.shift();
const index = ldr.indexOf(val);
const left = ldr.slice(0, index);
const right = ldr.slice(index + 1);
function Node() {
this.val = val;
this.left = createNode(dlr,left);
this.right = createNode(dlr, right)
}
const node = new Node();
return node;
}
function LRD(node, arr) {
arr.push(node.val);
if(node.right){
LRD(node.right, arr);
}
if(node.left){
LRD(node.left,arr)
}
}
const tree = createNode(dlr, ldr);
const lrd = []
LRD(tree, lrd);
console.log(lrd.reverse().join(''))
console