SOURCE

function DFS(node) {
    const nodes = [];
    if (node !== null) {
        nodes.push(node);
        const children = node.children;
        children.forEach(item => {
            nodes = nodes.concat(DFS(item));
        })
    }
    return nodes;
}

function BFS(node) {
    let nodes = []
    let queue = []
    if (node) {
        queue.push(node)
        while (queue.length) {
            let item = queue.shift()
            nodes.push(item)
            // 队列,先进先出
            let children = item.children
            for (let i = 0; i < children.length; i++) {
                queue.push(children[i])
            }
        }
    }
    return nodes
}
console 命令行工具 X clear

                    
>
console