Skip to content

Instantly share code, notes, and snippets.

@fogus
Created October 4, 2011 19:00
Show Gist options
  • Select an option

  • Save fogus/1262466 to your computer and use it in GitHub Desktop.

Select an option

Save fogus/1262466 to your computer and use it in GitHub Desktop.
An O(MG) version of Fibonacci on Node.js
function fibonnaci(n, done) {
if (n === 1 || n === 2) {
done(1);
} else {
process.nextTick(function() {
fibonnaci(n - 1, function(val1) {
process.nextTick(function() {
fibonnaci(n - 2, function(val2) {
done(val1 + val2);
});
});
});
});
}
};
fibonnaci(20, function(val) {
console.log('Final value ' + val);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment