Fibbonacci

In this example below you will see how to do a Fibbonacci with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by keesik, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright keesik ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Fibbonacci</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/keesik/fibbonacci-BdyjXx */
function fb(max, a, b, r) {
  r = r || [];
  a = a || 0;
  b = b || 1;

  if (r.length === 0) {

    r.push(a, b);
  }
  if (r.length < max) {

    var c = a + b;
    a = b;
    b = c;
    r.push(c);

    return fb(max, a, b, r);
  } else {
    return r;
  }
}

var fib = fb(10);

console.log(fib);

/**
 * Generator
*/

// function* fbGen (max, a, b) {
//     a = a || 0;
//     b = b || 1;

//     yield a;
//     yield b;

//     for (let i = 0; i < max; i++) {
//         const c = a + b;
//         a = b;
//         b = c;

//         yield c;
//     }
// }

Comments