const x = {
'A': ['C', 'D'],
'D': ['B'],
'B': ['E'],
'E': ['C', 'F']
}
const y = {
'A': ['B', 'F'],
'C': ['A', 'D'],
'D': ['B'],
'B': ['F']
}
function deal(obj, value){
let result = []
result.push(value)
let dep = obj[value]
for(let v in dep){
let p = deal(obj, dep[v])
for(let i = 0; i < p.length; i++){
let index = result.indexOf(p[i])
if(index > -1){
result.splice(index, 1)
}
}
result = result.concat(p)
}
return result
}
function dealDependency(obj){
let r_arr = []
let max_index = 0
let max_length = 0
let i = 0
for(let key in obj){
let r = deal(obj, key)
if(r.length > max_length){
max_length = r.length
max_index = i
}
r_arr.push(r)
i++
}
console.log(r_arr[max_index])
}
dealDependency(y)
console