Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
How to filter the array that contains objects with gaps key init
const cards = [
        {gaps: ["science", "education"]},
        {gaps: ["weapon"]},
        {gaps: ["figures", "character"]},
        {gaps: ["figures", "education"]},
      ]

function filter({})

Please help, there is an array when calling filter () this should return 5 groups into the console

  1. {gaps: ["science", "education"]} - science
  2. {gaps: ["science", "eenter code hereducation"]}, {gaps: ["figures", "education"]} - education
  3. {gaps: ["weapon"]} - weapon
  4. {gaps: ["figures", "character"]}, ["figures", "education"]} - figures
  5. {gaps: ["figures", "character"]} - character
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Using Array#reduce, iterate over cards while updating a Map where the key is the gap and the value is the list of objects having this gap in its gaps array.

In each iteration, you would iterate over the gaps using Array#forEach and update the Map:

const cards = [ {gaps: ["science", "education"]}, {gaps: ["weapon"]}, {gaps: ["figures", "character"]}, {gaps: ["figures", "education"]} ];

const gapsMap = cards.reduce((map, { gaps = [] }) => {
  gaps.forEach(gap => map.set(gap, [...(map.get(gap) || []), {gaps: [...gaps]}]));
  return map;
}, new Map);

console.log([...gapsMap]);
console.log(gapsMap.get("education"));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda