Skip to content

Instantly share code, notes, and snippets.

@islishude
Created June 4, 2019 01:05
Show Gist options
  • Save islishude/8165902d663ef293ed60dece319df2bd to your computer and use it in GitHub Desktop.
Save islishude/8165902d663ef293ed60dece319df2bd to your computer and use it in GitHub Desktop.
function fib_rec(n) {
if (n <= 1) {
return 1;
}
return fib_rec(n - 1) + fib_rec(n - 2);
}
function fib_loop(n) {
let [pre, cur] = [0, 1];
for (let i = 0; i < n; i++) {
[pre, cur] = [cur, pre + cur];
}
return cur;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment