Skip to content

Commit c6451c1

Browse files
author
Sruthi U
committed
Fixed factorial code formatting
1 parent 5b79e2c commit c6451c1

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎factorial.js‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
21
// Function to calculate factorial
32

43
function factorial(n) {
5-
if (!Number.isInteger(n) || n < 0) {
6-
throw new Error("Enter a non-negative integer");
7-
}
4+
if (!Number.isInteger(n) || n < 0) {
5+
throw new Error('Enter a non-negative integer')
6+
}
87

9-
if (n === 0 || n === 1) {
10-
return 1;
11-
}
8+
if (n === 0 || n === 1) {
9+
return 1
10+
}
1211

13-
return n * factorial(n - 1);
12+
return n * factorial(n - 1)
1413
}
1514

1615
// Example usage
17-
console.log(factorial(5)); // Output: 120
16+
console.log(factorial(5)) // Output: 120

0 commit comments

Comments
 (0)