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

167
Visualizações
Merge arrays of tasks containing matching elements

I'm fetching tasks from multiple APIs, namely Notion, Todoist and DevOps for now, and trying to merge them into a single collection of tasks so that I can sync them all.

First off, I normalize the tasks so they all have a similar signature like this for Notion:

return {
        title: task.properties.Name.title[0].text.content,
        status: status(), // Status enum mapping
        priority: priority(), // Priority enum mapping
        integrations: {
            'Notion': {
                id: task.id,
                original: task
            },
            'Todoist': {
                id: task.properties['Todoist'].number ?? undefined
            },
            'DevOps': {
                id: task.properties['DevOps'].number ?? undefined
            }
        }
    }

And I fetch them all into different arrays:

const fetchedTasks = Promise.all(integrations.map(integration => await integration.getTasks()))

But I don't know how to merge those arrays into a single one based on matching integration ids in an efficient manner. The only solution I could think of would be to loop over every item of every array, adding them to a new collection and checking that entire collection for a matching integration every time, but it just has too many loops to be the right solution.

Something like:

const merged = []
for (const collection of tasks) {
    for (const task of collection) {
        for (const integration of Object.keys(task.integrations)) {
            const mergedTask = merged.find(mergedTask => mergedTask.integrations[integration].id === task.integrations[integration].id)
            if (mergedTask)
                mergedTask.integrations[integration].original = task
            else
                merged.push(task)
        }
    }
}

So that at the end I have a list of tasks with the same signature as the normalized task but with all existing integrations having their original value set.

As as sidenote, are there patterns for syncing similar data from multiple sources? I coulnd't find anything that applied here.

about 4 years ago · Juan Pablo Isaza
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