Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda