Answers for "fibonacci generating function"

0

generator function fibonacci

// Fibonacci generator
function* fibonacci() {
  var a = 0;
  var b = 1;
  while (true) {
    yield a;
    a = b;
    b = a + b;
  }
}

// Instantiates the fibonacci generator
fib = fibonacci();

// gets first 10 numbers from the Fibonacci generator starting from 0
for (let i = 0; i < 10; i++) {
  console.log(i + ' => ' + fib.next().value);
}
Posted by: Guest on January-04-2021

Code answers related to "fibonacci generating function"

Python Answers by Framework

Browse Popular Code Answers by Language