var obj = {
}
var obj_length = Array.from({ length: 8 }, () => 0);
const arr = [
[1, 2],
[1, 5],
[2, 3],
[2, 6],
[3, 4],
[4, 7],
[5, 6],
[6,4]
]
var quq = [1];
for (var i = 0; i < arr.length; i++) {
obj_length[arr[i][1]] += 1;
if ((Object.keys(obj).includes(arr[i][0].toString())) == false) {
obj[arr[i][0]] = [arr[i][1]];
}
else {
obj[arr[i][0]].push(arr[i][1]);
}
}
console.log(obj)
var count=0
while (quq.length>0) {
var first = quq.shift();
// unshift/ shift 개념 헷갈리지말자..^^
console.log(first)
if(obj[first]){
for (var i = 0; i < obj[first].length; i++) {
var push_obj = obj[first];
//여기서 에러 났음//
obj_length[push_obj[i]] -= 1;
if (obj_length[push_obj[i]] == 0) {
quq.push(push_obj[i]);
console.log(quq)
}
}
}
}
//console.log(obj_length)