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

165
Views
Optimize time complexity - JavaScript

i need to optimize the time complexity of the given code kindly help.it is written in javascript.

for(let i=0;i<userList.length;i++){
   let clientValues = [];
   for(let j=0;j<userList[i].clients.length;j++){
      for(let k=0;k<clientList.length;k++){
         if(userList[i].clients[j] === clientList[k].client_id){
             clientValues.push(clientList[k].clientName);
         }
      }
    }
         userList[i].clients = clientValues;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming clientList is reasonably large, one option is to iterate over it only once to create a map that can be used as a constant-time lookup on each iteration of userList and userList[i].clients:

let clientMap = new Map(clientList.map(c => [c.client_id, c.clientName]))
userList.forEach(u => {
    u.clients = u.clients
       .map(c => clientMap.get(c))
       .filter(c => c !== undefined)
})
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!