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

128
Views
hashSet is including duplicates

This code is supposed to concat two elements inside of an Array without duplicating. The data.CamData contains multiple objects, each object has a CamID, Status, and other data. each (e) looks like this {Date: 1656533249379, State: 0}

    for (let i = 0; i < data.CamData.length; i++) {
        let hashSet = new Set();
        data.CamData[i].Events.forEach((e) => hashSet.add(e));
        state.camData[i].Events.forEach((e) => hashSet.add(e));
        data.CamData[i].Events = Array.from(hashSet);
      }

However, this code is just concatenating the two without getting rid of duplicates

I believe this is because even though the objects contain similar data they are the different objects. is there any other solution to this?

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

0

I think you can use Map or Object, you need to pick a key from your object, for instance 'Date' and set value by key

for (let i = 0; i < data.CamData.length; i++) {
        let hashMap = new Map();
        data.CamData[i].Events.forEach((e) => hashMap.set(e.Date, e));
        state.camData[i].Events.forEach((e) => hashMap.set(e.Date,e));
        data.CamData[i].Events = Array.from(hashMap.values());
      }

Hope this helps.

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!