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

108
Views
how to sum values ​of arrays in the same position

I have this line of code, how could I add the // "0[37][16]" to total 53 for example?

updateTotalMedidas() {
    this.ɵcart.medidaTotal = 0;
    for (const item of this.ɵcart.item) {
      let row_cm = (item.medidas[0] * item.medidas[1] * item.medidas[2]) * item.quantidade; // (3) [84, 40, 15] and (3) [30, 18, 8]
      let totalCmCubico = row_cm  // 50400 and 4320
      let raiz_cubica =  Math.round(Math.cbrt(totalCmCubico))  // 37 and  16
      this.ɵcart.medidaTotal += JSON.stringify([raiz_cubica]); // "0[37][16]"

    }
  }

if I remove the "[]" from this.ɵcart.medidaTotal it becomes 3716, so I put the [], but I don't understand why it stays in that format

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

0

This happens because you put everything inside JSON.stringify this converts objects into JSON strings. So in your current code mediaTotal will be first 0 then "37" and at last "3716". No need for that in your code.

You can just do this, because raiz_cubica is a number.

this.ɵcart.medidaTotal += raiz_cubica;
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!