求助大佬呀

2020-09-21 17:09:13 +08:00
 xiaoniuniu

/** 编写一个 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 }] }] }] }

990 次点击
所在节点    程序员
2 条回复
xiaoming1992
2020-09-21 21:30:28 +08:00
格式化都不做一下,太不上心了
tang123456
2020-09-22 10:34:44 +08:00
这咋看?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709107

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX