2022-10-13 13:49:03 +02:00
|
|
|
const factorial = function(n){
|
|
|
|
if(typeof(n) == "bigint") {
|
|
|
|
if(n == 1n || n == 0n){
|
|
|
|
return 1n
|
|
|
|
} else {
|
|
|
|
result = 1n
|
|
|
|
for(let i=1n; i<= n; i++){
|
|
|
|
result = result * i
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(n == 1 || n == 0){
|
|
|
|
return 1
|
|
|
|
} else {
|
|
|
|
result = 1
|
|
|
|
for(let i=1; i<= n; i++){
|
|
|
|
result = result * i
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { factorial }
|