Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | export function factorial(n) { let result = 1; for (let i = n; i > 1; i--) { result *= i; } return result; } export function factorialRecursive(n) { if (n < 2) { return 1; } return n * factorialRecursive(n - 1); } // --------------------------- TESTS --------------------------------------- console.time("factorial time: "); factorial(1000); console.timeLog("factorial time: "); console.time("recursive factorial time: "); factorialRecursive(1000); console.timeLog("recursive factorial time: "); |