/** 编写一个 js 方法根据输入实现输出 将 arr 转化为树形结构 treeObj 节点的 outputs 为下一节点的 inputs */
例子: // 输入 const arr = [{ name: 'test1', outputs: [1,2], inputs: [] }, { name: 'test2', outputs: [3], inputs: [1] }, { name: 'test3', outputs: [4], inputs: [2] }, { name: 'test4', outputs: [5], inputs: [3,4] }, { name: 'test5', outputs: [], inputs: [5] }] // 输出 const treeObj = { name: 'test1', outputs: [1,2], inputs: [] children: [{ name: 'test2', outputs: [3], inputs: [1], children: [{ name: 'test4', outputs: [5], inputs: [3,4], children: [{ name: 'test5', outputs: [], inputs: [5], children: null }] }] }, { name: 'test3', outputs: [4], inputs: [2], children: [{ name: 'test4', outputs: [5], inputs: [3,4], children: [{ name: 'test5', outputs: [], inputs: [5], children: null }] }] }] }
1
xiaoming1992 2020-09-21 21:30:28 +08:00 via Android
格式化都不做一下,太不上心了
|
2
tang123456 2020-09-22 10:34:44 +08:00
这咋看?
|