// iterative
// function factorialIterative(num) {
//   var factorial = 1;
//   for (var i = num; i > 0; i--) {
//     factorial *= i;
//   }
//   return factorial;
// }

function factorialIterative(num) {
  var factorial = 1;
  while (num > 0) {
    factorial *= num;
    num --;
  }
  return factorial;
}


// recursive
function factorialRecursive(num) {
  // base cases?
  if (num === 1 || num === 0) {
    return 1;
  }
  // console.log(num + " " + factorialRecursive(num - 1));
  // recursive factorial
  return num * factorialRecursive(num - 1);
}

@@ -1,16 +1,110 @@
 /
-/
+* %0A  given
  i
+n
 te
-rative
+ger n, return factorial for n%0A  5 -%3E 120%0A  4 -%3E 24%0A  3 -%3E 6%0A  2 -%3E 2%0A  1 -%3E 1%0A  0 -%3E 0%0A*/%0A
 %0A// 
@@ -399,22 +399,8 @@
 %0A%7D%0A%0A
-%0A// recursive%0A
 func
@@ -448,10 +448,8 @@
 case
-s?
 %0A  i
@@ -459,26 +459,12 @@
 num 
-=== 1 %7C%7C num === 0
+%3C= 2
 ) %7B%0A
@@ -474,17 +474,19 @@
  return 
-1
+num
 ;%0A  %7D%0A  
@@ -548,33 +548,8 @@
 ;%0A  
-// recursive factorial%0A  
 retu
@@ -584,12 +584,245 @@
 num - 1);%0A%7D%0A
+%0Alet memo = %5B%5D;%0A%0Afunction factorialMemoized(num) %7B%0A    if (num %3C= 2) %7B%0A      return num;%0A    %7D%0A    %0A    if (!(num in memo)) %7B%0A      memo%5Bnum%5D = factorialMemoized(num-1) * num;%0A    %7D%0A%0A    // console.log(memo);%0A    return memo%5Bnum%5D;%0A%7D%0A

Add memoization to factorial