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

102
Views
Simplifique el filtrado entre 2 matrices

Tengo el siguiente método de trabajo. Crea una matriz de elementos (que luego utilizo para completar un menú desplegable de selección) que no se han utilizado previamente en el resto de la matriz de formularios. Me pregunto si hay una forma más corta y elegante de hacer todo esto.

 uniqueChoiceLocaleItems(currentValue) { // Create an array of all the ids already taken. ie. ["en", "fr", "es"]; var idsTaken = []; this.myForm['controls'].languages['controls'].forEach((x, index) => { if ((x['controls'].id.value != currentValue)) { idsTaken.push(x['controls'].id.value); } }); // Loop through our main master 'this.locales' array which has ALL the locales in the world and filter out all the ids from the 'idsTaken' array var uniqueItems = []; this.locales.forEach((x, index) => { if (idsTaken.indexOf(x.code) !== -1) { } else { uniqueItems.push(x); } }); return uniqueItems; }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar un Set y su devolución de llamada de constructor para crearlo. Luego elimine currentValue de ese conjunto (no importa si realmente estaba en él o no). Finalmente use filter :

 uniqueChoiceLocaleItems(currentValue) { var idsTaken = new Set( this.myForm.controls.languages.controls.map(x => x.controls.id.value) ); idsTaken.delete(currentValue); return this.locales.filter(x => !idsTaken.has(x.code)); }
about 4 years ago · Juan Pablo Isaza Report

0

Versión simple y modificada.

 var idsTaken = this.myForm["controls"].languages["controls"].filter( (x) => x["controls"].id.value != currentValue ).map((x) => x["controls"].id.value); var uniqueItems = this.locales.filter((x) => idsTaken.indexOf(x.code) === -1);
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!