🔧 Updated factorial func to be more concise
This commit is contained in:
parent
d30743e03c
commit
d88ce386a9
2 changed files with 2 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue