From 285d2b08da905496e9fe9c2f31fd3d8501d6893b Mon Sep 17 00:00:00 2001 From: Ejiah Date: Fri, 22 Jan 2021 12:44:52 +0700 Subject: [PATCH] Move the (num > 0) if condition to the end --- Maths/Factorial.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Maths/Factorial.js b/Maths/Factorial.js index c3a0162e4..29b416a67 100644 --- a/Maths/Factorial.js +++ b/Maths/Factorial.js @@ -18,11 +18,6 @@ const calcRange = (num) => { } const calcFactorial = (num) => { - if (num > 0) { - const range = calcRange(num) - const factorial = range.reduce((a, c) => a * c, 1) - return `The factorial of ${num} is ${factorial}` - } if (num === 0) { return 'The factorial of 0 is 1.' } @@ -32,6 +27,11 @@ const calcFactorial = (num) => { if (!num) { return 'Sorry, factorial does not exist for null or undefined numbers.' } + if (num > 0) { + const range = calcRange(num) + const factorial = range.reduce((a, c) => a * c, 1) + return `The factorial of ${num} is ${factorial}` + } } export { calcFactorial }