Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda