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

172
Visualizações
Where is the result of each function call stored in this factorial method?

Here is an object with a method that will return the factorial of a number via recursion. What I can't wrap my head around is where the value of the factorialized variable is being stored when the function calls itself again and multiplies inputNumber by itself -1. Could someone explain this to me?

const Calculate = {
  factorial(inputNumber) {
    if (inputNumber < 2) { return 1 };
    const factorialized = inputNumber * this.factorial(inputNumber - 1);
    
    return factorialized;
    }
  }

Calculate.factorial(5);


about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Many language has Memory Heap to save value for their operations, etc.

Image your function will execute 3 times:

  • the the result from 1th execution will be allocate to [k] position of Memory Heap
  • then the 2th execution will allocate to [k+1] position
  • the 3th execution will allocate to [k+2] position and will be calculate the value and save into [k+2] position
  • then the 2th function will use the [k+2] position to calculate their result
  • then the 1th function will use the [k+1] position to calculate their result
  • finally will return the value

Some addtion information

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