Created
September 26, 2014 03:20
-
-
Save davidbj/24d6bc9ea1d22607032b to your computer and use it in GitHub Desktop.
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
| function demo(num){ | |
| if(num<=1){ | |
| return 1; | |
| } | |
| return num*demo(num-1); | |
| } | |
| alert(demo(5)) //stdout:120 | |
| Execute the process: | |
| 1.return 5*demo(4) | |
| 2.return 4*demo(3) | |
| 3.return 3*demo(2) | |
| 4.return 2*demo(1) | |
| 5.if(num<=1) == true return 1 | |
| 6.return 1*1 return 1 | |
| 7.return 2*1 return 2 | |
| 8.return 3*2 return 6 | |
| 9.return 4*6 return 24 | |
| 10.return 5*24 return 120 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment