小编tar*_*ran的帖子

JavaScript - 根据依赖关系树排序

我必须展示一组相互依赖的图像.例如

 Image A depends on no one
 Image B depends on A
 Image C depends on A and B
 Image D depends on F
 Image E depends on D and C
 Image F depends on no one
Run Code Online (Sandbox Code Playgroud)


我有一个像这样的javascript对象:

const imageDependencies = {
    A: [],
    B: ['A'],
    C: ['A', 'B'],
    D: [F],
    E: ['D', 'C'],
    F: []
}
Run Code Online (Sandbox Code Playgroud)


我需要通过依赖项来获取所有图像名称.此示例的结果可能是以下任何一个:

//   so first yo get the value of A. Once you have it you can get the value of B. Once you …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting topological-sort typescript

7
推荐指数
3
解决办法
338
查看次数