Created
October 7, 2019 06:46
-
-
Save hoodwink73/3657e10d37673922a4d9b5c48e0a08a8 to your computer and use it in GitHub Desktop.
Trampolined Fibonnaci
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
var trampoline = (fn) => | |
(...args) => { | |
var result = fn(...args); | |
while (typeof result === "function") { | |
result = result() | |
} | |
return result | |
} | |
var fibonnaci = trampoline((n) => { | |
if (n < 2) { | |
return n; | |
} else { | |
return () => { | |
return fibonnaci(n/*?*/ - 1) + fibonnaci(n - 2) | |
} | |
} | |
}) | |
fibonnaci(5) //? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment