Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created March 22, 2017 09:47
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 a-eid/b5f4c8d8830386a66a233f23c52c7907 to your computer and use it in GitHub Desktop.
Save a-eid/b5f4c8d8830386a66a233f23c52c7907 to your computer and use it in GitHub Desktop.
implementation of tail recursive and no tail recursive factorial
function fac(n){
if( n == 0) return 1
return n * fac(n-1)
}
function fac2(n){
return (function tmp( n , a){
if(n == 0) return a
return tmp(n-1 , a * n)
})(n , 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment