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

94
Views
How to navigate through all the values of an array of object

I'm trying to make a function that will get every key "quantidade", take their values, and multiply for the corresponding "tecnologia" key of the parent key, if the object has the "A" key in "tecnologia", it will multiply for the "A" value in the first object, this is what i did so far:

function calcula (tabela, arvore) {
    for (i = 0; i < arvore.length; i++) {
        arrFilhos = [`["filhos"][x]`]
        arrArvore = [`arvore[i]`]
        arrLevel = []

        for(x = 0; x < arvore[i]["filhos"].length; x++){
            if ("filhos" in eval(arrArvore[0])){
                console.log(eval(arrArvore.toString().replace(/,/g , "")))
                arrArvore.push(arrFilhos[0])
            }
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm assuming that tecnologia only exists in the last node

function calculaCusto (tabelaCusto, arvoreArquitetura) {
   const cb = (prev, next) => {
     if(next.tecnologia) {
       return prev + next.quantidade * tabelaCusto[next.tecnologia];
     }
     else if(next.filhos){
       return prev + next.quantidade * next.filhos.reduce(cb, 0);
     } else { //doesn't have tecnologia nor filhos
       return;
     }
   }

   return arvoreArquitetura.reduce(cb, 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!