Skip to content

Instantly share code, notes, and snippets.

@ddeaguiar
Forked from christianromney/gist:983038
Created May 20, 2011 14:40
Show Gist options
  • Save ddeaguiar/983044 to your computer and use it in GitHub Desktop.
Save ddeaguiar/983044 to your computer and use it in GitHub Desktop.
Naive fibonacci
var fib, num;
fib = function(x) {
if (x > 2) {
return fib(x - 1) + fib(x - 2);
}
return x;
};
console.log((function() {
var _results;
_results = [];
for (num = 0; num <= 10; num++) {
_results.push(fib(num));
}
return _results;
})());
fib = (x) ->
return (fib(x - 1) + fib(x - 2)) if x > 2
x
console.log (fib(num) for num in [0..10])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment