UNPKG

lazzy.ts

Version:

Fast and lightweight library for lazy operations with iterable objects.

24 lines 673 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fibonacci = void 0; function* fibonacci(minimum = 1) { let [prev, next] = findClosestFibonacci(minimum); while (true) { const current = prev; prev = next; next += current; const reply = yield current; if (reply != null) { [prev, next] = findClosestFibonacci(reply); } } } exports.fibonacci = fibonacci; ; function findClosestFibonacci(n, prev = 0, next = 1) { if (next < n) { return findClosestFibonacci(n, next, prev + next); } return [next, prev + next]; } //# sourceMappingURL=fibonacci.js.map