Skip to content

Instantly share code, notes, and snippets.

@greyhands2
Created January 25, 2023 09:57
Show Gist options
  • Save greyhands2/d1a84e4ac5a6d18f5d8608d447f32f05 to your computer and use it in GitHub Desktop.
Save greyhands2/d1a84e4ac5a6d18f5d8608d447f32f05 to your computer and use it in GitHub Desktop.
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