V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
xiaoniuniu
V2EX  ›  程序员

求助大佬呀

  •  
  •   xiaoniuniu · Sep 21, 2020 · 1895 views
    This topic created in 2048 days ago, the information mentioned may be changed or developed.

    /** 编写一个 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 replies    2020-09-22 10:34:44 +08:00
    xiaoming1992
        1
    xiaoming1992  
       Sep 21, 2020 via Android
    格式化都不做一下,太不上心了
    tang123456
        2
    tang123456  
       Sep 22, 2020
    这咋看?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2578 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:01 · PVG 15:01 · LAX 00:01 · JFK 03:01
    ♥ Do have faith in what you're doing.