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

177
Views
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 answers
Answer question

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 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!