Skip to content

Instantly share code, notes, and snippets.

View greyhands2's full-sized avatar
🎯
Focusing

Osemwota Osagie Anthony greyhands2

🎯
Focusing
View GitHub Profile
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 {
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];