Skip to content

Commit 7030086

Browse files
committed
feat: added compareStrings & computeFactorial func
1 parent d67600c commit 7030086

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ export function compareStrings(a: string, b: string): number {
1111
// The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1
1212
// if it is greater, and 0 if the strings are equal.
1313
const distance = computeLexicographicDistance(a, b);
14-
1514
// TODO(you): Finish this method.
1615

17-
return 0;
16+
if (distance < 0) {
17+
return -1;
18+
} else if (distance > 0) {
19+
return 1;
20+
} else {
21+
return 0;
22+
}
1823
}
1924

2025
/**
@@ -24,7 +29,11 @@ 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+
let result: number = n;
33+
for (let i = result; i > 0; i--) {
34+
result = i * (i - 1);
35+
}
36+
return result;
2837
}
2938

3039
/**

0 commit comments

Comments
 (0)