Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to login with api in react js 
Javascript :: jquery timepicker get value onchange 
Javascript :: jquery with npm in laravel 
Javascript :: javascript math random floor 
Javascript :: how avoid populate mongoose return password 
Javascript :: js import and export 
Javascript :: this.setstate is not a function 
Javascript :: remove element from array 
Javascript :: tsconfig build only files and not src 
Javascript :: jquery get element tag 
Javascript :: Quoting Strings with Single Quote 
Javascript :: wordpress ajax trigger code 
Javascript :: max value from array in javascript 
Javascript :: how to get all attributes of an element in jquery 
Javascript :: state hook is not updating react 
Javascript :: search to enter key react 
Javascript :: popup in browser js 
Javascript :: innertext of input js 
Javascript :: what is last index of array 
Javascript :: Find the next perfect square! 
Javascript :: watch file in changes in webpack 
Javascript :: javascript set object key by variable 
Javascript :: firefox freeze page 
Javascript :: forof 
Javascript :: separate last character string javascript 
Javascript :: format date in javascript 
Javascript :: babel start command nodejs 
Javascript :: form data 
Javascript :: get input value angular 
Javascript :: js add function to array 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =