function factorial(n){
if(n === 1) {
return 1
}
return n * factorial(n - 1)
} |
V
function factorial(3){
if(3 === 1) {
return 1
}
return 3 * factorial(3 - 1)
} |
V
function factorial(2){
if(2 === 1) {
return 1
}
return 2 * factorial(2 - 1)
} |
V
function factorial(1){
if(1 === 1) {
return 1
}
return 1 * factorial(1 - 1)
}
/// caston wants taylor info -> ariunaa -> kerridene -> taylor
/// caston wants taylor info <- ariunaa <- kerridene <- taylor
factorial(3)
// for(let i = 0; ; i++){
// console.log(i)
// } /// -> infinite loop
// function factorialIncrement(n){
// let result = 1;
// if(n < 1){
// return NaN
// }
// for(let i = 1; i <= n; i++ ){
// result *= i
// }
// return result
// }
// 3 -> 2 -> 1
// 3! 3 x 2 x 1
// first iteration => 1 *= i -> 1
// second iteration => 1 *= i -> 2
// third iteration => 2 *= i -> 3
// result -> 6
// function factorialDecrement(n){
// let result = 1;
// for(let i = n; i > 1; i--){
// result *= i;
// }
// return result
// }
// console.log(factorialDecrement(3))
// console.log(factorialIncrement(3))
// function decrement(n) {
// let result = 1;
// while (n > 0) {
// result *= n;
// n--;
// }
// return result;
// }
// decrement(3)
Last active
June 15, 2023 12:44
-
-
Save CastonPursuit/59d225b5a2c38231773bbe7af4364bda to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment