Advertisement
vladovip

Factorial Division_ver2 - JS fundamentals

Feb 5th, 2022
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function factorialDivision(num1, num2) {
  2.  
  3.     function factorialCalculator(number) {
  4.     let result = 1;
  5.     while (number != 1) {
  6.       result *= number;
  7.       number -= 1;
  8.     }
  9.     return result;
  10.   }
  11.   let finalDivisionResult = factorialCalculator(num1) / factorialCalculator(num2)
  12.   console.log(finalDivisionResult.toFixed(2));
  13. }
  14. factorialDivision(5, 2);
  15.  
  16.  
  17.  
  18. // A function can call itself. For example, here is a function that computes factorials recursively:
  19. /*
  20. function factorial(n) {
  21.     if ((n === 0) || (n === 1))
  22.       return 1;
  23.     else
  24.       return (n * factorial(n - 1));
  25.   }
  26.   */
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement