Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Вычисление факторила
- n! = 6! = 1 * 2 * 3 * 4 * 5 * 6
- */
- function factorial(num) {
- if (num === 0) return 0;
- if (num === 1) return 1;
- let last = 1;
- for (var i = 1; i < num; i++) {
- last = last * (i + 1)
- }
- return last;
- }
- console.log(factorial(0)) // 0
- console.log(factorial(1)) // 1
- console.log(factorial(6)) // 720
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement