Created
January 25, 2023 09:56
-
-
Save greyhands2/7a1e41814a372002e89bc93bd530d51a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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