Move the (num > 0) if condition to the end

This commit is contained in:
Ejiah
2021-01-22 12:44:52 +07:00
committed by GitHub
parent 57e20c551c
commit 285d2b08da

View File

@ -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 }