Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created January 26, 2014 02:32
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 roman01la/8627381 to your computer and use it in GitHub Desktop.
Save roman01la/8627381 to your computer and use it in GitHub Desktop.
JS Recursion vs Trampoline
countDown = (n) ->
console.log(n)
if n > 0
countDown(n-1)
else
console.log('DONE!')
countDown(1000000)
countDown = (n) ->
console.log(n)
if n > 0
() -> countDown(n-1)
else
console.log('DONE!')
trampoline = (fun, num) ->
result = fun(num)
while typeof result is 'function'
result = result()
result
trampoline(countDown, 1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment