Created
March 22, 2017 09:47
-
-
Save a-eid/b5f4c8d8830386a66a233f23c52c7907 to your computer and use it in GitHub Desktop.
implementation of tail recursive and no tail recursive factorial
This file contains 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
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