11 lines
145 B
Text
11 lines
145 B
Text
|
|
def factorial( n ) =
|
||
|
|
if n < 0
|
||
|
|
error( 'factorial: n should be non-negative' )
|
||
|
|
else
|
||
|
|
res = 1
|
||
|
|
|
||
|
|
for i <- 2..n
|
||
|
|
res *= i
|
||
|
|
|
||
|
|
res
|