Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created April 9, 2019 11:07
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 lukaskollmer/33cb495579217a2257b5bb0663250bdd to your computer and use it in GitHub Desktop.
Save lukaskollmer/33cb495579217a2257b5bb0663250bdd to your computer and use it in GitHub Desktop.
const fib_it = n => {
let [a, b] = [0, 1];
while (n-- > 0) {
[a, b] = [b, a + b];
}
return a;
}
const fib_rec = n => {
if (n < 2) return n;
return fib_rec(n-1) + fib_rec(n-2);
}
const fib_trec = n => {
const imp = (acc, l, i) => {
if (i < 1) return acc;
return imp(acc + l, acc, i-1);
}
return imp(0, 1, n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment