Created
April 2, 2017 14:36
-
-
Save zeraf29/61cabcd23ae3afaf04359326e09210ac 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
var factorial = function(n) { | |
// n이 0일 경우 1을 리턴(항등원) | |
if(n===0){ | |
return 1; | |
} | |
// 0이 아닐 경우, n보다 작은 수의 팩토리얼 계산(재귀함수 호출) | |
// 최종의 경우 n*(n-1)!=n! 와동일 | |
return n*factorial(n-1); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment