Skip to content

Instantly share code, notes, and snippets.

@Gwash3189
Created June 13, 2015 05:31
Show Gist options
  • Save Gwash3189/61edd11444c0f1eddb3c to your computer and use it in GitHub Desktop.
Save Gwash3189/61edd11444c0f1eddb3c to your computer and use it in GitHub Desktop.
Recursive fibonacci sequence
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