Advertisement
avr39ripe

jsRecursionBasics

Feb 11th, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <h1 id="mesg"></h1>;
  9.  
  10.     <script>
  11.         'use strict'
  12.         /*
  13.          0! = 1
  14.          n! = n * (n - 1)!
  15.          (n - 1)! = (n - 1) * ( n - 2)!
  16.  
  17.          
  18.  
  19.            3! -> 1 * 2 * 3
  20.          */
  21.  
  22.         function fakt(n) {
  23.             if (n == 0) { return 1; }
  24.             return n * fakt(n - 1);
  25.         }
  26.         /*
  27.          fakt(3) -> 3 * fakt(3 -1)
  28.          fakt(2) -> 2 * fakst( 2 - 1)
  29.          fakt(1) -> 1 * fakt(1 -1 )
  30.          fakt(0) -> 1
  31.  
  32.          fakt(3) -> 3 * 2
  33.          fakt(2) -> 2 * 1
  34.          fakt(1) -> 1 * 1
  35.          fakt(0) -> 1
  36.          */
  37.         console.log(fakt(3));
  38.     </script>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement