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

95
Views
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 answers
Answer question

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 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!