Created
April 9, 2019 11:07
-
-
Save lukaskollmer/33cb495579217a2257b5bb0663250bdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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