Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda