This file contains hidden or 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 edgesToUndirectedGraph = (edges) => { | |
| let graph = {}; | |
| edges.forEach(elem=> elem.forEach((e,i,arr)=>{ | |
| let dupArr = [...arr]; | |
| current = dupArr.splice(i,1); | |
| if(Array.isArray(graph[current])){ | |
| graph[current]=[...graph[current], ...dupArr] | |
| } else { |
This file contains hidden or 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]; |