let graph = {};
for(let [a, b] of edge) {
graph[a] ? graph[a].push(b) : graph[a] = [b];
graph[b] ? graph[b].push(a) : graph[b] = [a];
}
// 입력
[[3, 6], [4, 3], [3, 2], [1, 3], [1, 2], [2, 4], [5, 2]]
// 출력
{ '1': [ 3, 2 ],
'2': [ 3, 1, 4, 5 ],
'3': [ 6, 4, 2, 1 ],
'4': [ 3, 2 ],
'5': [ 2 ],
'6': [ 3 ] }
https://programmers.co.kr/learn/courses/30/lessons/49189?language=javascript