Trust you doing great !!!1
Trying to create a directed graph between airports using AdjacencyList shown in YT Video using Map function in Node.js and ran the below code in online editor pramp.com,problem is why Map is showing the output as Empty...It should show up a Map like this ,also if you can explain what this line of code does routes.forEach(route => addEdge(...route)) why 3 dots and fat arrow =>
Question is is this problem with online editor Pramp.com ? I dont want to use VSCode hence using online editor
//The Data
const airports = 'PHX BKK OKC JFK LAX MEX EZE HEL LOS LAP LIM'.split(' ');
const routes = [
['PHX','LAX'],
['PHX','JFK'],
['JFK','OKC'],
['JFK','HEL'],
['MEX','LAX'],
['MEX','BKK'],
['MEX','LIM'],
['MEX','EZE'],
['LIM','BKK'],
];
//The Graph
const adjacencyList = new Map();
//add-node
function addnode(airport){
adjacencyList.set(airport,[]);
//Add edge,undirected
function addEdge(origin,destination){
adjacencyList.get(origin).push(destination);
adjacencyList.get(destination).push(origin);
}
//Create the Graph
airports.forEach(addNode);
routes.forEach(route => addEdge(...route))
}
console.log(adjacencyList);
In Pramp editor i see this
Many Thanks In advance
Carolyn

