@KK998/

Recursion-factorial

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Write two functions that finds the factorial of any number. One should use recursive, the other should just use a for loop
function findFactorialRecursive(number) { 
  if(number === 2){
    return 2
  }
  return number * findFactorialRecursive(number - 1) 
}
findFactorialRecursive(5)
// 4 * 3 * 2 * 1










/* function findFactorialIterative(number) {

  let sum = number;
  for(let i = number - 1; i > 0; i--){
    sum *= i
  }
  return sum;
}
findFactorialIterative(6)
 */
Native Browser JavaScript