Skip to content

Commit 79ac727

Browse files
committed
Update .env.test, lesson7.ts, and part_g.ts
1 parent 888672a commit 79ac727

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

lesson_07/conditionals/.env.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
HW_VERSION=your homework version here
1+
HW_VERSION=G

lesson_07/conditionals/src/lesson7.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ 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+
}
19+
if (distance > 0) {
20+
return 1
21+
}
22+
23+
return 0
1624

17-
return 0;
18-
}
1925

2026
/**
2127
* Computes the factorial of the given value of `n`.

lesson_07/conditionals/src/part_g.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
* @returns
66
*/
77
export function findLargestNumber(numbers: number[]): number {
8-
return 0;
9-
}
8+
let largest = numbers[0];
9+
10+
// loop through numbers using index
11+
for (let i = 1; i < numbers.length; i++) {
12+
if (numbers[i] > largest) {
13+
largest = numbers[i];
14+
}
15+
}
16+
17+
return largest;
18+
1019

1120
/**
1221
* Determines if a string is a palindrome (reads the same forwards and backwards).
@@ -16,7 +25,18 @@ export function findLargestNumber(numbers: number[]): number {
1625
* @returns
1726
*/
1827
export function isPalindrome(text: string): boolean {
19-
return false;
28+
//clean up input text and replace all spaces from the string
29+
// change all the uppercase letters to lowercase
30+
const clean = text.replace(/\s+/g, "").toLowerCase();
31+
// clean = amanaplanacanalpanama
32+
33+
for (let i = 0; i < clean.length / 2; i++) {
34+
if (clean[i] !== clean[clean.length - 1 - i]) {
35+
return false;
36+
}
37+
}
38+
return true;
39+
}
2040
}
2141

2242
/**
@@ -36,5 +56,5 @@ export function daysUntilBirthday(
3656
birthMonth: number,
3757
birthDay: number
3858
): number {
39-
return 0;
59+
throw new Error("Not implemented yet");
4060
}

0 commit comments

Comments
 (0)