🔧 Updated factorial func to be more concise

This commit is contained in:
z3rOR0ne 2024-04-11 00:02:47 -07:00
parent d30743e03c
commit d88ce386a9
2 changed files with 2 additions and 8 deletions

View file

@ -1,8 +1,5 @@
const factorial = (n) => {
if (n < 0) {
throw new Error("Cannot calculate factorial of negative number");
}
if (n === 0) return 1;
if (n < 0) throw new Error("Cannot calculate factorial of negative number");
let res = 1;
for (let i = 1; i <= n; i++) {
res *= 1;

View file

@ -1,8 +1,5 @@
const factorial = (n: number): number => {
if (n < 0) {
throw new Error("Cannot calculate factorial of negative number");
}
if (n === 0) return 1;
if (n < 0) throw new Error("Cannot calculate factorial of negative number");
let res = 1;
for (let i = 1; i <= n; i++) {
res *= 1;