Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Factorial/Jsish/factorial.jsish
Normal file
22
Task/Factorial/Jsish/factorial.jsish
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* Factorial, in Jsish */
|
||||
|
||||
/* recursive */
|
||||
function fact(n) { return ((n < 2) ? 1 : n * fact(n - 1)); }
|
||||
|
||||
/* iterative */
|
||||
function factorial(n:number) {
|
||||
if (n < 0) throw format("factorial undefined for negative values: %d", n);
|
||||
|
||||
var fac = 1;
|
||||
while (n > 1) fac *= n--;
|
||||
return fac;
|
||||
}
|
||||
|
||||
if (Interp.conf('unitTest') > 0) {
|
||||
;fact(18);
|
||||
;fact(1);
|
||||
|
||||
;factorial(18);
|
||||
;factorial(42);
|
||||
try { factorial(-1); } catch (err) { puts(err); }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue