1.递归如何停止?
if(...){
...
}
else if(...){
递归
}
2.递归是否有返回值?
----可使用Object的引用类型特性,无需return
3.平铺和递归的使用场景?
===== >>>> 3.1 递归适用场景,一层下面套多层 <<<<======
数据结构形式:
[{
"type": "RuleActionInstance",
"key": "0",
"inputValue": "",
"children": [{
"type": "webRuleConditions",
"key": "0-0",
"value": "条件",
"children": []
}, {
"type": "webRuleAction",
"key": "0-1",
"value": "实例",
"children": []
}]
}]
======>>>> 3.2 平铺的适用场景,就是一个数组里面的数据结构 <<<<===
======== >>>> 将递归转换为平铺函数
let transformTreeNodeToPlaintArray = (allRuleChild, plainArray) => {
for (let i = 0, length = allRuleChild.length; i < length; i++) {
plainArray.push(allRuleChild[i]);
if (!!allRuleChild[i].children) {
transformTreeNodeToPlaintArray(allRuleChild[i].children, plainArray);
}
}
}