UNPKG

483 BJavaScriptView Raw
1// TODO: BUG: this co implementation does not recurse properly - cause yet to be determined
2
3
4var co = require('co');
5
6
7// WARNING: BAD CODE!! THIS IMPL IS HUGELY INEFFICIENT. It's purpose is purely
8// to exercise recursive behaviour for testing and evaluation purposes.
9var fibonacci = co(function* (n) {
10 if (n <= 1) return 1;
11 var operands = yield [fibonacci(n - 1), fibonacci(n - 2)];
12 return operands[0] + operands[1];
13});
14
15
16module.exports = fibonacci;