Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda