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

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

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