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

179
Visualizações
how to get intersection between twos list in nodejs

inside a get request fucntion to mysql db and After two awaits on promises to get two lists (tab1 and tab2) filled, i want to get the intersection between them. tab1 and tab2 are lists of strings.

const app = express();
var intersectionBetween = function(a1,a2){
  return  a1.filter(function(n) { return a2.indexOf(n) !== -1;});
};
app.get('/getPackages', async (req, res) => {
  var tab1= []
  var tab2= []
  const promiseIntersection = (a1, a2) => {
    return new Promise((res, rej)=> {
      intersectionBetween(a1, a2, function (err, resultsss){
        if (err) rej(err);
        return res(resultsss)
      });
    })
  }
  const intersectionb = await promiseIntersection(tab1, tab2);
  console.log("efe",intersectionb)
  res.send('Posts fetched...');

});


app.listen(3000, () => console.log("Express server is runnig at port: 3000"))

I wanted to get the intersection but when I go in the browser under '/getPackages' the browser runs forever without returning anything. Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After two awaits on promises to get two lists (tab1 and tab2) filled, you can directly call it and get intersection. There is nothing async.

app.get('/getPackages', async (req, res) => {
        var tab1= []
        var tab2= []
        const intersectionb = intersectionBetween(tab1, tab2);
        console.log("efe",intersectionb)
        res.send('Posts fetched...');
    
    });
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