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

178
Views
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 answers
Answer question

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