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

229
Views
Cómo evitar el bucle anidado usando TypeScript

Estoy trabajando en una aplicación en la que quiero obtener los nombres de usuario de la matriz employeeList. Aquí lo obtengo usando un bucle anidado, pero esta no es una buena práctica. Aquí está mi código

 let _empList = await this.empService.getEmployeesList(); let taskEvents = await this.taskService.renderedTaskGridData( _tasksData, undefined ); let associatesList = []; for (let proj of this.projectsData) { let projTasks = [...taskEvents.filter((x) => x.ProjectId === proj.Id)]; _empList.forEach((x) => { projTasks.forEach((y) => { y.AssociatedUsersId.forEach((z) => { if ((x.Id = z)) { associatesList.push(`${x.FirstName} ${x.LastName}`); } }); }); }); }

Necesito obtener la lista usando las mejores prácticas.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Continuaré y asumiré que el problema que le preocupa es la complejidad asintótica (es decir, cuánto aumenta su tiempo de ejecución en relación con el tamaño de su entrada).

La forma en que lo resolvería sería hacer un intercambio de tiempo y espacio, así:

 let associatesList = []; const projectIds = new Set(this.projectsData.map((proj) => proj.Id)); const userIds = new Set( taskEvents .filter((task) => projectIds.has(task.ProjectId)) .flatMap((event) => event.AssociatedUsersId) ); const employees = _empList .filter((employee) => userIds.has(employee.Id)) .map((employee) => `${employee.FirstName} ${employee.LastName}`);
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!