aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/v4/fact.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/v4/fact.js')
-rw-r--r--tests/manual/v4/fact.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/manual/v4/fact.js b/tests/manual/v4/fact.js
new file mode 100644
index 0000000000..56727d6fb1
--- /dev/null
+++ b/tests/manual/v4/fact.js
@@ -0,0 +1,22 @@
+function fact1(n) {
+ if (n > 0)
+ return n * fact1(n - 1);
+ else
+ return 1
+}
+
+function fact2(n) {
+ return n > 0 ? n * fact2(n - 1) : 1
+}
+
+function fact3(n) {
+ var res = 1;
+ for (var i = 2; i <= n; i=i+1)
+ res = res * i;
+ return res;
+}
+
+print("fact1(12) = ", fact1(12))
+print("fact2(12) = ", fact2(12))
+print("fact3(12) = ", fact3(12))
+