Constructor
new Fibonacci()
- Source
Examples
new Fibonacci();
import { Fibonacci } from "201flaviosilva-utils";
const f = new Fibonacci();
for (i = 0; i < 10; i++) console.log(f.next()); // 1,2,3,5,8,13,21,34,55,89
for (i = 0; i < 5; i++) console.log(f.before()); // 55,34,21,13,8
Members
sequence :Array.<number>
Contains the current state of the sequence
Type:
- Array.<number>
- Source
Methods
before() → {number}
Return the next number in the fibonacci sequence
- Source
Returns:
- Type:
- number
Example
const f = new Fibonacci()
f.next(); // 1
f.next(); // 2
f.before() // 1
current() → {number}
Return last number in sequence
- Source
Returns:
- Type:
- number
Example
new Fibonacci().current(); // 3
next() → {number}
Return the next number in the fibonacci sequence
- Source
Returns:
- Type:
- number
Example
new Fibonacci().next(); // 1