```function checkDpes(list) {
const depMap = {};
const findNode = function (key) {
return list.find(it => it.key === key)
}
const findDeps = function (key, deps, path) {
deps.forEach(it => {
if (key === it) {
console.log('有循环依赖')
}
if (depMap[key].indexOf(it) === -1) {
depMap[key].push(it)
const node = findNode(it)
if (node.deps && node.deps.length) {
findDeps(key, node.deps, [...path, it])
}
}
})
}
list.forEach(it => {
depMap[it.key] = []
findDeps(it.key, it.deps || [], [])
});
return depMap;
}
// 测试用例
var list = [
{
key: 'A',
deps: ['B', 'C', 'D']
},
{
key: 'B',
deps: ['C']
},
{
key: 'C',
deps: ['D']
},
{
key: 'D',
deps: ['E']
},
{
key: 'E',
}
]
var res = checkDpes(list)
console.log(res)