Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
How to get the Directed Graph Output using Node js

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 =>

enter image description here

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

enter image description here

Many Thanks In advance

Carolyn

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ellipsis (...) is the spread operator. It takes an array, for example [origin, destination] and basically turns it into two vars origin, destination. Calling

addEdge(...[origin,destination])

is like calling

addEdge([origin,destination][0], [origin,destination][1])

Which is the same as

addEdge(origin,destination)

The "fat arrow" operator is a lambda (anonymous function) definition.

(a,b) => { console.log(a, b) }

is the same as

function (a,b) { console.log(a, b) }

Its just a shorter way to define functions without names. Usually simple ons that are given as parameters. In this case to the forEach call.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!