Skip to content

Commit 7ee51a4

Browse files
author
“Tezz03”
committed
feat: upload lesson_07 test
1 parent c668fa2 commit 7ee51a4

File tree

4 files changed

+109
-144
lines changed

4 files changed

+109
-144
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=E

lesson_07/conditionals/package-lock.json

Lines changed: 31 additions & 135 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lesson_07/conditionals/src/lesson7.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,68 @@ 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.
16-
15+
if (distance < 0) {
16+
return -1;
17+
}
18+
else if (distance > 0) {
19+
return 1;
20+
}
21+
else {
1722
return 0;
23+
}
1824
}
1925

2026
/**
2127
* Computes the factorial of the given value of `n`.
2228
*
2329
* @param n The value for which to compute the factorial.
2430
* @return The factorial of n.
31+
*
32+
* 5! = 5*4! factorial equation
2533
*/
2634
export function computeFactorial(n: number): number {
27-
return 0;
35+
if (n === 0 || n === 1) {
36+
return 1;
37+
}
38+
else {
39+
return n * computeFactorial(n-1);
40+
}
2841
}
2942

43+
44+
3045
/**
3146
* Returns an array of the first `n` Fibonacci numbers starting from 1.
3247
*
3348
* @param n The first `n` of Fibonacci values to compute.
3449
* @return An array containing the first `n` Fibonacci values.
3550
*/
3651
export function getFirstNFibonacciNumbers(n: number): number[] {
37-
return [];
52+
53+
for (let i = 0; i < n; i++) {
54+
if (n === 0)
55+
return [];
56+
57+
else if (n === 1) {
58+
return [1];
59+
}
60+
61+
else if (n === 2) {
62+
return[1,1];
63+
}
64+
else {
65+
const fib = getFirstNFibonacciNumbers(n -1);
66+
fib.push(fib[fib.length - 1] + fib [fib.length - 2]);
67+
return fib;
68+
}
69+
}
70+
71+
return[];
72+
73+
74+
75+
76+
3877
}
3978

4079
/**
@@ -58,6 +97,14 @@ export function binarySearch(
5897
}
5998

6099
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.
100+
if (values[pivotIndex] === value) {
101+
return pivotIndex;
102+
} else if (values[pivotIndex] > value) {
103+
return binarySearch(values,start, pivotIndex - 1, value);
104+
} else {
105+
return binarySearch(values, pivotIndex + 1, end, value);
106+
return -1;
107+
}
61108

62109
// TODO(you): Finish implementing this algorithm
63110

lesson_07/conditionals/src/part_e.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
* @param char
66
* @returns
77
*/
8+
89
export function isUppercase(char: string): boolean {
9-
return false;
10-
}
10+
if(['A', 'B', 'C', 'D', 'E', 'F','G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S','T', 'U', 'V', 'W', 'X', 'Y', 'Z'].includes(char)) {
11+
return true;
12+
} else {
13+
return false;
14+
}
15+
}
16+
1117

1218
/**
1319
* Determine if a person is eligible for a driving license (age and test passed).
@@ -17,7 +23,12 @@ export function isUppercase(char: string): boolean {
1723
* @returns
1824
*/
1925
export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
20-
return false;
26+
if (age >= 18 && passedTest) {
27+
return true;
28+
}
29+
else {
30+
return false;
31+
}
2132
}
2233

2334
/**
@@ -29,5 +40,16 @@ export function canGetDriverLicense(age: number, passedTest: boolean): boolean {
2940
* @returns
3041
*/
3142
export function isStoreOpen(day: string, hour: number): boolean {
32-
return false;
43+
const weekCaseDay = day.toLowerCase();
44+
45+
46+
if(weekCaseDay === 'sunday') {
47+
return false;
48+
}
49+
else if (['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'].includes(weekCaseDay) && hour >= 21 || hour < 9)
50+
return false;
51+
else {
52+
return true;
53+
}
3354
}
55+

0 commit comments

Comments
 (0)