神女生涯元是梦,小姑居处本无郎。
扁平数组转换树结构
- 输入
1 | let arr = [ |
- 输出结果
1 | [ |
代码实现
- 双层循环
1 | function arrChangeTree(arr) { |
- 单层循环
1 | function arrChangeTree(arr) { |
- 递归
1 | const getChildren = (data, result, pid) => { |
神女生涯元是梦,小姑居处本无郎。
1 | let arr = [ |
1 | [ |
1 | function arrChangeTree(arr) { |
1 | function arrChangeTree(arr) { |
1 | const getChildren = (data, result, pid) => { |