Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda