题目:
过滤掉一个树形结构中不含给定的 filtername 的结点
eg例子🌰:[{name: 'A', children: [ {name: 'B'} ]},{name: 'C'}] 以 filtername='B' 过滤后则成为 [{name: 'A', children: [ {name: 'B'} ]}]
原理:
//原理:
function fn(a){
if(a>3) return
console.log(a);
b=a+1;
fn(b);
console.log(a)
}
fn(1) // 1 2 3 3 2 1
实现思路:
1. 从上至下:使用 forEach() 对tree进行遍历,使用 if hasOwnProperty('children') deep+1 得到tree的深度
2. 从下至上:!hasOwnProperty('children') 后,判断是否 == 目标结点
1. 如果 !=,什么都不做,继续向上走
2. 如果 ==,准备把该node加入到new_tree中
1. node 需作为 child-node1
2. 先放入 temp_tree 中
3. 当