mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-06 18:33:59 -05:00
Added function to get factorial of number
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user