5-3 ?迴?叫?可變個數????

JavaScript Ƥ]iH䴩jIs]Recursive Calls^A]NOA@ӨƥiHIsۤvCҦpA󶥭ƨӻAڭ̦ n! = n*(n-1)!A]ڭ̥iHg@ӻjơAҦpG

Example]funcFact.htm^G

lɮפepUG

lɡ]funcFact.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>Hj覡i涥ƪp</h2>
<hr>

<script>
function fact(n){		// Hj覡i涥ƪp
	if (n==0) return(1);	// 
	return(n*fact(n-1));	// jIs
}

for (i=10; i<19; i++)
	document.write(i+"! = "+fact(i)+"<br>");
</script>

<hr>
</body>
</html>

Hint
jMnΡA{X]²uAObiBɡA|ӱܦh CPU ΰO귽A]DƵc]Ҧp Tree^ΰD]Ҧp Hanoi Tower^NAXjƪϥΡA_h٬Oɶq֥ΡC

JavaScript ƥiuiܭӼƪJ޼ơv (Input Arguments of Variable Length)AoO]J޼ƥisbƪ󥻨@]Ωʽ^ arguments AҦs񪺸ƬO@Ӱ}CAJavaScript iΨ arguments.length ou޼ƭӼơCҦpAڭ̥ig@ӨơAӱNJ޼ƥHLǦCΦǦC覡ܡAƪlXpUG

lɡ]list.js^G]ǦϰUYi^
// iܤ޼ƭӼƪ禡d
function list(type) {
	document.write("<" + type + "l>");
	for (var i=1; i<list.arguments.length; i++)
		document.write("<li>" + list.arguments[i]);
	document.write("</" + type + "l>");
}

bWzƤAtype OĤ@Ӥ޼ơ]iHO "o" άO "u"^Aӫ򪺨LJ޼ơAhOH list.arguments oӰ}CӪܡA䤤 list OƪW١CҦpAlist.arguments[0] NO type Alist.arguments[1] NOb type ᪺Ĥ@Ӥ޼ơAlist.arguments[2] hOĤGӡA̦C

ϥΤWzƥiͥNӼƪLǩMǦCApUG

Example]list01.htm^G

lXG

lɡ]list01.htm^G]ǦϰUYi^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>iPJӼƪ</h2>
<hr>

<script src="list.js"></script>

Hulist("u", "", "l", "īG")vͪLǦCG
<script>
list("u", "", "l", "īG");
</script>

Hulist("o", "ax", "ȭx", "ux", "ԩ")vͪǦCG
<script>
list("o", "ax", "ȭx", "ux", "ԩ");
</script>

<hr>
</body>
</html>


JavaScript {]pPΡGΩΤ