V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaoniuniu
V2EX  ›  程序员

求助大佬呀

  •  
  •   xiaoniuniu · 2020-09-21 17:09:13 +08:00 · 956 次点击
    这是一个创建于 1285 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    2 条回复    2020-09-22 10:34:44 +08:00
    xiaoming1992
        1
    xiaoming1992  
       2020-09-21 21:30:28 +08:00 via Android
    格式化都不做一下,太不上心了
    tang123456
        2
    tang123456  
       2020-09-22 10:34:44 +08:00
    这咋看?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2734 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 12:45 · PVG 20:45 · LAX 05:45 · JFK 08:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.