Skip to content

Instantly share code, notes, and snippets.

function buildGraph(edges) {
let graph = Object.create(null);
function addEdge(from, to) {
if (graph[from] == null) {
graph[from] = [to];
} else {
graph[from].push(to);
}
console.log(from, to);
console.log(graph[from]); //vs console.log(graph); why does printing the entire graph here print the completed graph on the second call, even though it shouldn't be fully constructed until the last call?