Last active
December 14, 2015 12:38
-
-
Save InPermutation/5087433 to your computer and use it in GitHub Desktop.
Using throw.js, show how to tail-call optimize a recursive function using ...exceptions?!
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 throwup = require('throw').throwup, makecallable = require('throw').makecallable; | |
| var recurse = throwup(_recurse); | |
| var callable_recurse = makecallable(_recurse); | |
| var result = callable_recurse(parseInt(process.argv[2], 10) || 5000, 0); | |
| console.log('found', result); | |
| function _recurse(n, j) { | |
| if(n>0) return recurse(n-1, j+1); | |
| else return j; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment