Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (firstNum, secondNum) {
- function calculateFactorial() {
- let num1 = 1;
- let num2 = 1;
- for (let i = firstNum; i > 0; i--) {
- num1 *= i;
- }
- for (let i = secondNum; i > 0; i--) {
- num2 *= i;
- }
- return `${(num1 / num2).toFixed(2)}`;
- }
- console.log(calculateFactorial());
- }
- Решение с рекурсия:
- function solve (firstNum, secondNum) {
- function factorial(num) {
- if (num === 0) {
- return 1;
- } else {
- return (num * factorial(num - 1));
- }
- }
- console.log(`${(factorial(firstNum) / factorial(secondNum)).toFixed(2)}`);
- }
- Или:
- function solve (firstNum, secondNum) {
- function factorial(num) {
- return (num < 2) ? 1 : factorial(num - 1) * num;
- }
- console.log(`${(factorial(firstNum) / factorial(secondNum)).toFixed(2)}`);
- }
Add Comment
Please, Sign In to add comment