Skip to content

Commit 9c1d5c5

Browse files
updated computeFactorial
1 parent 1e8fa55 commit 9c1d5c5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export function compareStrings(a: string, b: string): number {
2222
* Computes the factorial of the given value of `n`.
2323
*
2424
* @param n The value for which to compute the factorial.
25-
* @return The factorial of n.
25+
* @return The factorial of n, or 0 if n is negative.
2626
*/
2727
export function computeFactorial(n: number): number {
2828
if (n < 0) {
29-
throw new Error("Factorial is not defined for negative numbers.");
29+
return 0; // Return 0 for negative numbers as per the test case
3030
}
3131
if (n === 0 || n === 1) {
3232
return 1;

0 commit comments

Comments
 (0)