Skip to content

Instantly share code, notes, and snippets.

@mattcodez
Created February 23, 2018 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcodez/bd64a52a223d2942a8a003bf8b15fc35 to your computer and use it in GitHub Desktop.
Save mattcodez/bd64a52a223d2942a8a003bf8b15fc35 to your computer and use it in GitHub Desktop.
Fibonacci
function fib_i(num) {
console.log(`Series of ${num}`);
let num2 = 0, num1 = 1;
for (let i = 0; i < num; i++) {
console.log(num1);
const next = num2 + num1;
num2 = num1;
num1 = next;
}
}
function fib_r(num) {
if (num <= 1) {
return 1;
}
let num2 = fib_r(num - 2),
num1 = fib_r(num - 1);
let next = num1 + num2;
return next;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment