Created
June 13, 2015 05:31
-
-
Save Gwash3189/61edd11444c0f1eddb3c to your computer and use it in GitHub Desktop.
Recursive fibonacci sequence
This file contains 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
function fib(prev=[], loop=100, cb=function(){}) { | |
if(!prev.length){ | |
prev.unshift(0); | |
prev.unshift(1); | |
} | |
prev.unshift(prev[1] + prev[0]); | |
cb(prev); | |
if(loop === 0){ | |
return prev; | |
} | |
return fib(prev,(loop-1)); | |
} | |
console.log(fib()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment