Skip to content

Commit 285d2b0

Browse files
authored
Move the (num > 0) if condition to the end
1 parent 57e20c5 commit 285d2b0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Maths/Factorial.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ const calcRange = (num) => {
1818
}
1919

2020
const calcFactorial = (num) => {
21-
if (num > 0) {
22-
const range = calcRange(num)
23-
const factorial = range.reduce((a, c) => a * c, 1)
24-
return `The factorial of ${num} is ${factorial}`
25-
}
2621
if (num === 0) {
2722
return 'The factorial of 0 is 1.'
2823
}
@@ -32,6 +27,11 @@ const calcFactorial = (num) => {
3227
if (!num) {
3328
return 'Sorry, factorial does not exist for null or undefined numbers.'
3429
}
30+
if (num > 0) {
31+
const range = calcRange(num)
32+
const factorial = range.reduce((a, c) => a * c, 1)
33+
return `The factorial of ${num} is ${factorial}`
34+
}
3535
}
3636

3737
export { calcFactorial }

0 commit comments

Comments
 (0)