Skip to content

Instantly share code, notes, and snippets.

@marcogbarcellos
Created February 7, 2017 17:03
Show Gist options
  • Save marcogbarcellos/cc479742d84da24066d519b88eea4225 to your computer and use it in GitHub Desktop.
Save marcogbarcellos/cc479742d84da24066d519b88eea4225 to your computer and use it in GitHub Desktop.
Returns the value of the Nth value of the fibonnacci sequence.
function fibonnacci(n) {
if (n === 0) {
return 0;
}
else if (n === 1) {
return 1;
}
else {
return fibonnacci(n-1)+fibonnacci(n-2);
}
}
// Values of the Fth number of the fibonnacci sequence
// F0: 0 ; F1: 1; F2: 1; F3: 2; F4: 3; F5: 5; F6: 8; F7: 13; F8: 21;
// F9: 34; F10: 55; F11: 89; F12: 144; F13: 233; F14: 377; F15: 610;
// F16:987; F17: 1597; F18: 2584; F19: 4181; F20: 6765;
var numb = 15; // should return 610
console.log(fibonnacci(numb));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment