Advertisement
nher1625

recursion_by_definition

Jun 3rd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function factorial(number) {
  2.     var currentNum = null;
  3.     if (number == 1) {
  4.         print("number is now 1");
  5.         return number;
  6.     }
  7.     else {
  8.         currentNum = number * factorial(number - 1);
  9.         print("Current number is", number);
  10.         print("Current return of the function is", currentNum);
  11.         return currentNum;
  12.     }
  13. }
  14.  
  15. print(factorial(5));
  16. // when a function is called recursively, the results of the function's computation
  17. // are temporarily suspended while the recursion is in progress.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement