JSFiddle - React, Tailwind, and code Playground
by evgkch
JavaScript
class Node {
constructor(id){
this.id = id;
this.children = null;
}
addChild(child){
if (this.children)
this.children.push(child);
else
this.children = [child];
}
}
function deepSearch(tree, id){
if (tree.id == id)
return tree;
else if (tree.children)
{
return tree.children.find(child=>deepSearch(child, id));
}
}