2.0.1 • Published 7 years ago

fibonacci-generator-function v2.0.1

Weekly downloads
6
License
ISC
Repository
github
Last release
7 years ago

Fibonacci Generator Function - JavaScript

Generator function yielding the next number in a fibonacci sequence. Optional starting param.

Installation

npm install fibonacci-generator-function

Usage

const fibGen = require('fibonacci-generator-function');
const fib1 = fibGen();
console.log( fib1.next() ); // { value: 1, done: false }
console.log( fib1.next() ); // { value: 2, done: false }
console.log( fib1.next().value ); // 3
console.log( fib1.next().value ); // 5
console.log( fib1.next().value ); // 8
// etc...
// Specified starting value 
const fib3 = fibGen(3);
console.log( fib3.next() ); // { value: 3, done: false }
console.log( fib3.next() ); // { value: 6, done: false }
console.log( fib3.next().value ); // 9
console.log( fib3.next().value ); // 15
console.log( fib3.next().value ); // 24
// etc...