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

149
Visualizações
For loop calling recursive function looping infinitely

I'm trying to make a program that would draw bones that are connected to each other at their ends, just by recursively running through that bone's children. The issue is that when a bone has more than two children it attempts to draw the second one an infinite number of times.

var bones={
    torso:{
        attached:["arm","arm2"]
    },
    arm:{
        attached:[]
    },
    arm2:{
        attached:[]
    }
}

drawBone("torso")
function drawBone(bone){
    console.log(bone)
    let attBones = bones[bone].attached;
    for(i = 0; i < attBones.length; i++){
        drawBone(attBones[i])
    }
}

From what I've found, i inside the for loop gets stuck at 1 somehow. I'm not super familiar with recursion, so there might be something fundamentally wrong I'm doing.

about 4 years ago · Juan Pablo Isaza
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