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

194
Views
¿Cómo calcular el promedio de todas las propiedades de los objetos sin especificarlas explícitamente por nombre?

Estoy tratando de encontrar una forma sólida de calcular el promedio de las propiedades de los objetos en caso de que haya demasiados para especificarlos explícitamente por su nombre.

Encontré esta buena esencia que ayuda en caso de que solo tengamos algunas propiedades:

 const someData = [ { height: 176, weight: 87 }, { height: 190, weight: 103 }, { height: 180, weight: 98 } ] // for height var sumHeight = (prev, cur) => ({height: prev.height + cur.height}); var avgHeight = someData.reduce(sumHeight).height / someData.length; console.log(avgHeight); // => gives 182 // for weight var sumWeight = (prev, cur) => ({weight: prev.weight + cur.weight}); var avgWeight = someData.reduce(sumWeight).weight / someData.length; console.log(avgWeight); // => gives 96

Pero este método está limitado en términos de escalado si tenemos muchas propiedades, por ejemplo:

 const someDataExtended = [ { height: 176, weight: 87, salary: 100000, age: 20, numOfCats: 2 }, { height: 190, weight: 103, salary: 100050, age: 40, numOfCats: 0 }, { height: 180, weight: 98, salary: 20345, age: 50, numOfCats: 1 } ]

¿Cómo puedo promediar todas las propiedades sin especificarlas por nombre? Idealmente, me gustaría mapear sobre someDataExtended sin mutar los datos iniciales, sino generar un resumen como:

 const finalSummary = { height: 182, weight: 96, salary: 73465, numOfCats: 1 }
about 4 years ago · Juan Pablo Isaza
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!