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

243
Vistas
Solución optimizada para una ejecución más rápida: NodeJs

Estoy tratando de optimizar una solución que se usa para agrupar los objetos según el valor presente en otra matriz ( mapping ) que está escrita como NodeJS.

 function workerFunction(report) { const groupedArray = [] const granularityKey = 'Month' const mapping = ['TestField1', 'TestField2'] //will be dynamic based on json input let activeIIndex = 0; while (activeIIndex < report.length) { const index = groupedArray .findIndex(item => mapping .every((column) => item[column] === report[activeIIndex][column])) if (index === -1) { report[activeIIndex][report[activeIIndex][granularityKey]] = report[activeIIndex]['Cost'] groupedArray.push(report[activeIIndex]) } else { groupedArray[index][report[activeIIndex][granularityKey]] = report[activeIIndex]['Cost'] } activeIIndex++; } return groupedArray }

La entrada a la función del workerFunction(report) se verá así (por lo general, el tamaño de la matriz será superior a 300k),

 [ { "TestField1":"value", "TestField2":"value2", "Cost":12.5555, "Month":10 }, { "TestField1":"value3", "TestField2":"value4", "Cost":142.5555, "Month":10 }, { "TestField1":"value6", "TestField2":"value4", "Cost":15.87, "Month":10 }, { "TestField1":"value3", "TestField2":"value4", "Cost":16.5555, "Month":11 } ]

El resultado esperado después de pasar este objeto json a través workerFunction será

 [ { "TestField1":"value", "TestField2":"value2", "Cost":12.5555, "Month":10, "10":12.5555 }, { "TestField1":"value3", "TestField2":"value4", "Cost":142.5555, "Month":10, "10":142.5555, "11":16.5555 }, { "TestField1":"value6", "TestField2":"value4", "Cost":15.87, "Month":10, "10":15.87 }, ]
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