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

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

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