Skip to content

Instantly share code, notes, and snippets.

@greyhands2
Created January 25, 2023 09:56
Show Gist options
  • Save greyhands2/7a1e41814a372002e89bc93bd530d51a to your computer and use it in GitHub Desktop.
Save greyhands2/7a1e41814a372002e89bc93bd530d51a to your computer and use it in GitHub Desktop.
const edgesToDirectedGraph = (edges) => {
let graph={};
edges.forEach((elem)=>{
let first= elem.shift();
if(Array.isArray(graph[first])) {
graph[first]=[...elem,...graph[first]];
} else {
graph[first]=[...elem];
}
});
return graph;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment