This is an old revision of the document!
Tree
export function inorderTraversal<T>(
root: node<T>,
fn: (n: T) => boolean,
newTree?: node<T>
) {
newTree = {
value: root.value,
children: [],
};
console.log(root.value);
if (root.children) {
for (const n of root.children) {
if (fn(root.value)) {
if (fn(n.value)) {
newTree.children!.push(inorderTraversal(n, fn, newTree, newTree));
} else {
for (const nn of n.children) {
newTree.children!.push(inorderTraversal(nn, fn, newTree, newTree));
}
}
}
}
}
return newTree;
}