Created
January 25, 2023 09:57
-
-
Save greyhands2/d1a84e4ac5a6d18f5d8608d447f32f05 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 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 { | |
graph[current] = [...dupArr]; | |
} | |
})); | |
return graph; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment