From d88ce386a9791a0a5e2652995a5c3d946759036d Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Thu, 11 Apr 2024 00:02:47 -0700 Subject: [PATCH] :wrench: Updated factorial func to be more concise --- utils/utils.js | 5 +---- utils/utils.ts | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/utils/utils.js b/utils/utils.js index 18c32d80..e936c80c 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -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; diff --git a/utils/utils.ts b/utils/utils.ts index 1e23248a..da16412e 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -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;