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

171
Views
Encuentre una forma eficiente de filtrado de dos matrices (ArrayA y ArrayB) para hacer una tercera ArrayC

¿Alguien puede ayudarme a encontrar una forma más rápida de filtrar el siguiente ArrayC (vea a continuación a qué debería ser igual). ArrayA se explica por sí mismo. ArrayB tiene dentro de cada elemento un objeto 'data' que tiene una propiedad "target" como un cadena "\_teacher" que puedo filtrar en función de una variable global "userType" para distinguir a los estudiantes de los profesores. "filter_klas_1371" ==> filter_{GroepType }_{GroepID} from Array A. Esta propiedad cambia. rompiendo la cadena y el filtrado me ha dado dolor de cabeza, así que si hay formas más rápidas y eficientes de filtrar esto, házmelo saber.

 let userType='teacher' arrayA: [{ "ID": 1, "GroepID": 1371, "GroepType": "klas" }, { "ID": 2, "GroepID": 1372, "GroepType": "klas" }, { "ID": 3, "GroepID": 1375, "GroepType": "graad" } ] araayB: [{ "id": "bd5b12ba-b433-4610-801e-e0b78fa72ff8", data: { "target": "_teacher", "filter_klas_1371": "true" } }, { "id": "gggfdgdba-gfgg-fff-ggg-7657657676", data:{ "target": "_teacher_student", "filter_klas_1375": "true" } } { "id": "uuuykllk-b433-4610-801e-8888888776", data: { "target": "_student", "filter_klas_1372": "true" } } { "id": "jkjkjkklk-jkhjk-66567-666-99977", data: { "target": "_teacher_student", "filter_klas_1372": "true" } }, { "id": "zzzzzzz-b433-4610-801e-8888888776", data: { "target": "_teacher", "filter_klas_1372": "true" } }, ] //should get arrayC:[{ "id": "bd5b12ba-b433-4610-801e-e0b78fa72ff8", data: { "target": "_teacher", "filter_klas_1371": "true" } }, { data: { "id": "jkjkjkklk-jkhjk-66567-666-99977", "target": "_teacher_student", "filter_klas_1372": "true" } }, { "id": "zzzzzzz-b433-4610-801e-8888888776", data: { "target": "_teacher", "filter_klas_1372": "true" } } ]

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

0

Si entiendo correctamente, le gustaría filtrar arrayB según el tipo de usuario y los valores en arrayA. Sugiero hacer una matriz de todos los filter_{groepType}_{groepId} con el mapa de matriz:

 const filterKeys = arrayA.map(group => `filter_${group.GroepType}_${group.GroepID}`);

Luego puede verificar si uno de esos valores está configurado como clave en las claves de arrayB, usando una intersección de array con un par de filtros. Puedes hacer esto de más maneras:

 arrayC = arrayB.filter(item => { const intersect = Object.keys(item.data).filter(key => filterKeys.includes(key)); return intersect.length > 0; // you can additionally add the filter for target here })
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!