Skip to content

Commit e3446a1

Browse files
chore: updates Karens lesson_07.ts
1 parent 4b44a61 commit e3446a1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@ export function compareStrings(a: string, b: string): number {
2727
* @return The factorial of n.
2828
*/
2929
export function computeFactorial(n: number): number {
30-
return 0;
30+
// worked with Davis to complete this coding problem
31+
// edge cases
32+
if (n === 0) {
33+
return 1;
34+
}
35+
if (n === 1) {
36+
return 1;
37+
}
38+
if (n < 0) {
39+
return 0;
40+
}
41+
let result = 1;
42+
for (let i = 2; i <= n; i++) {
43+
result *= i;
44+
}
45+
return result;
3146
}
3247

3348
/**

0 commit comments

Comments
 (0)