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

196
Views
JS: organice los datos de los objetos en función de las ocurrencias

Necesito organizar de alguna manera los datos a continuación en un formato determinado como el siguiente:

 const data: {} = [ { emotion: 3, intensity: 1 }, { emotion: 5, intensity: 2 }, { emotion: 3, intensity: 1 }, { emotion: 3, intensity: 2 }, ] const dataone = _.groupBy(data, 'emotion') const entries: any = Object.entries(dataone) console.log(entries)

A este formato:

 [{emotion: 3, 1: 2, 2: 1, total: 3}, {emotion: 5, 1: 0, 2: 1, total: 1}]

Le agradecería si pudiera proporcionar alguna ayuda o enlace a algunas preguntas similares.

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

0

Puede agrupar y actualizar los valores.

 const data = [{ emotion: 3, intensity: 1 }, { emotion: 5, intensity: 2 }, { emotion: 3, intensity: 1 }, { emotion: 3, intensity: 2 }], result = Object.values(data.reduce((r, { emotion, intensity }) => { r[emotion] ??= { 1: 0, 2: 0, emotion, total: 0 }; r[emotion][intensity]++; r[emotion].total++; return r; }, {})); console.log(result);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

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!