# fibonacci-fast

0.2.0 • Public • Published

# fibonacci-fast

A fast node.js module for working with the Fibonacci sequence

## Usage

Documentation can be found here

### fibonacci.get(k)

Get the kth index of the Fibonacci sequence

The `result` will be a JavaScript `object` containing the following:

Where `number` is a big number representing Fibonacci[3000] and `next` is also a big number representing Fibonacci[3001]. The `ms` is the amount of time (in milliseconds) that it took to get the result.

### fibonacci.find(num)

Find the index of a given Fibonacci number

The `result` will be the same form as the result of the `fibonacci.get(n)` method, so the `index` can be retrieved easily with `result.index`. This also means that the `number` and `next` values are returned in the `result` variable as well.

### fibonacci.is(num)

Checks if a given number is a Fibonacci number

### fibonacci.iterator([k, n])

Create a Fibonacci sequence iterator. Where `k` and `n` are optional parameters defining the starting index of the iterator and the max number of iterations respectively. If `k` is not given, then the iterator will start at index 0. If `n` is not given the iterator will allow infinite iterations.

The result:

The result:

### fibonacci.array(k0, k1)

Grab an array of the Fibonacci sequence. Where `k0` is the starting index, and `k1` is the ending index.

NOTE: the number at `k1` will not be included in the `array`

The result will be an array of objects with the following form:

In order to get an array containing the actual Fibonacci numbers and not the objects, you could map the array like so:

and the resulting array would look like this:

## Fast Doubling Algorithm

This module utilizes the fast doubling algorithm which allows for much faster calculations of Fibonacci numbers than the traditional recurrence method.

The fast doubling algorithm takes Θ(log n) operations, and the recurrence algorithm takes Θ(n).

## Big.js

The fibonacci-fast module utilizes the big.js library to handle large numbers.

## Package Sidebar

### Install

`npm i fibonacci-fast`

### Repository

github.com/CraigH2013/fibonacci-fast

2

0.2.0