-
-
Save ddeaguiar/983044 to your computer and use it in GitHub Desktop.
Naive fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
})()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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