Added function to get factorial of number

This commit is contained in:
2021-06-01 18:31:32 -04:00
parent 0c3d7ee0c0
commit 7ef12495c4
2 changed files with 45 additions and 1 deletions

View File

@@ -642,3 +642,19 @@ export function gcdBig(num1: bigint, num2: bigint){
}
return num1 | num2;
}
//Return the factorial of the number passed in
export function factorial(num: number): number{
let fact: number = 1;
for(let cnt = 1;cnt <= num;++cnt){
fact *= cnt;
}
return fact;
}
export function factorialBig(num: bigint): bigint{
let fact: bigint = 1n;
for(let cnt = 1n;cnt <= num;++cnt){
fact *= cnt;
}
return fact;
}