Created
November 23, 2017 16:05
-
-
Save slugbyte/50a04f0f8e1f4c7632b9f08a9e040b07 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
let trampoline = (fn) => (...args) => { | |
let next = fn(...args) | |
while(next instanceof Function) | |
next = next() | |
return next | |
} | |
let range = (start, end, result=[]) => { | |
result.push(start) | |
if(start === end) return result | |
return () => range(start < end ? ++start : --start, end, result) | |
} | |
let result = trampoline(range)(5, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment