Skip to content

Commit 9ef3c5e

Browse files
committed
feat: lesson07/impelement functions
1 parent 8b5348c commit 9ef3c5e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export function compareStrings(a: string, b: string): number {
1212
// if it is greater, and 0 if the strings are equal.
1313
const distance = computeLexicographicDistance(a, b);
1414

15-
// TODO(you): Finish this method.
15+
if (distance < 0) {
16+
return -1;
17+
}
18+
if (distance > 0) {
19+
return 1;
20+
}
1621

1722
return 0;
1823
}
@@ -24,8 +29,10 @@ export function compareStrings(a: string, b: string): number {
2429
* @return The factorial of n.
2530
*/
2631
export function computeFactorial(n: number): number {
27-
return 0;
32+
if (n === 0) return 1;
33+
return n * computeFactorial(n - 1);
2834
}
35+
console.log(computeFactorial(5)); // Output: 120
2936

3037
/**
3138
* Returns an array of the first `n` Fibonacci numbers starting from 1.

0 commit comments

Comments
 (0)