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

248
Views
¿Cómo obtener el resultado total de ventas por cpf?

Me gustaría sumar las ventas totales por CPF, logré separar el CPF pero borré cómo hacer la suma ahora, vea mi código a continuación

 var vendas = [{cpf: "14382435021", amount: 34.5 }, { cpf: "79785337006", amount: 12 }, { cpf: "79785337006", amount: 23.16 }, { cpf: "14382435021", amount: 46.4 }, { cpf: "88835414059", amount: 26.2 }, { cpf: "88835414059", amount: 199.9 }, { cpf: "79785337006", amount: 18.16 } ] var resultados = {}; for(var i = 0; i < vendas.length; i++){ if(vendas[i].cpf){ if(!resultados[vendas[i].cpf]){ resultados[vendas[i].cpf] = [] } resultados[vendas[i].cpf].push(vendas[i]); } } console.log(resultados)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

<script> var vendas = [{cpf: "14382435021", amount: 34.5 }, { cpf: "79785337006", amount: 12 }, { cpf: "79785337006", amount: 23.16 }, { cpf: "14382435021", amount: 46.4 }, { cpf: "88835414059", amount: 26.2 }, { cpf: "88835414059", amount: 199.9 }, { cpf: "79785337006", amount: 18.16 } ] var result = []; vendas.reduce(function(res, value) { if (!res[value.cpf]) { res[value.cpf] = { cpf: value.cpf, amount: 0 }; result.push(res[value.cpf]) } res[value.cpf].amount += value.amount; return res; }, {}); console.log(result) </script>
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!