Skip to content

Instantly share code, notes, and snippets.

@slugbyte
Created November 23, 2017 16:05
Show Gist options
  • Save slugbyte/50a04f0f8e1f4c7632b9f08a9e040b07 to your computer and use it in GitHub Desktop.
Save slugbyte/50a04f0f8e1f4c7632b9f08a9e040b07 to your computer and use it in GitHub Desktop.
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