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

89
Views
¿Una forma más eficiente de encontrar el máximo de múltiples objetos similares en la matriz JS?

¿Existe un método de matriz (o cualquier otra forma realmente) para agrupar objetos dentro de una matriz por una propiedad y sumar por otra? Entonces devolver el máximo?

 let array = [ {ticker:'AAPL',val:400}, {ticker:'IBM',val:200}, {ticker:'AAPL',val:500}, {ticker:'SBUX',val:800}, ] let obj = {} array.forEach( h => { obj[h.ticker] = obj[h.ticker] || 0; obj[h.ticker] += h.val }) let temp = Object.keys( obj ).map(function ( key ) { return obj[key] }); console.log(Math.max(...temp)) // returns 900

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si solo desea modificarlo para usar reduce en lugar de forEach , puede hacerlo:

 let obj = array.reduce((a,b) => ({...a, [b.ticker]: (a[b.ticker] || 0) + b.val}), {});
about 4 years ago · Juan Pablo Isaza Report
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!