Skip to content

Commit 34b01bc

Browse files
committed
feat: add lesson07
1 parent b9be8c7 commit 34b01bc

File tree

4 files changed

+91
-18
lines changed

4 files changed

+91
-18
lines changed

lesson_06/quiz/src/lesson5.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Lesson5 {
3838
[AnswerChoice.C, "To insert an image"],
3939
[AnswerChoice.D, "To create a paragraph"],
4040
]),
41-
AnswerChoice.UNANSWERED,
41+
AnswerChoice.B,
4242
);
4343
}
4444

@@ -52,7 +52,7 @@ export class Lesson5 {
5252
[AnswerChoice.C, "alt"],
5353
[AnswerChoice.D, "href"],
5454
]),
55-
AnswerChoice.UNANSWERED,
55+
AnswerChoice.C,
5656
);
5757
}
5858

@@ -66,7 +66,7 @@ export class Lesson5 {
6666
[AnswerChoice.C, "<div>"],
6767
[AnswerChoice.D, "<link>"],
6868
]),
69-
AnswerChoice.UNANSWERED,
69+
AnswerChoice.B,
7070
);
7171
}
7272

@@ -80,7 +80,7 @@ export class Lesson5 {
8080
[AnswerChoice.C, "<span>"],
8181
[AnswerChoice.D, "<br>"],
8282
]),
83-
AnswerChoice.UNANSWERED,
83+
AnswerChoice.B,
8484
);
8585
}
8686

@@ -94,7 +94,7 @@ export class Lesson5 {
9494
[AnswerChoice.C, "Computer Style Sheets"],
9595
[AnswerChoice.D, "Cascading System Sheets"],
9696
]),
97-
AnswerChoice.UNANSWERED,
97+
AnswerChoice.B,
9898
);
9999
}
100100

@@ -108,7 +108,7 @@ export class Lesson5 {
108108
[AnswerChoice.C, "text-color"],
109109
[AnswerChoice.D, "background-color"],
110110
]),
111-
AnswerChoice.UNANSWERED,
111+
AnswerChoice.B,
112112
);
113113
}
114114

@@ -122,7 +122,7 @@ export class Lesson5 {
122122
[AnswerChoice.C, "/* this is a comment */"],
123123
[AnswerChoice.D, "<!-- this is a comment -->"],
124124
]),
125-
AnswerChoice.UNANSWERED,
125+
AnswerChoice.C,
126126
);
127127
}
128128

@@ -136,7 +136,7 @@ export class Lesson5 {
136136
[AnswerChoice.C, "text-size"],
137137
[AnswerChoice.D, "text-style"],
138138
]),
139-
AnswerChoice.UNANSWERED,
139+
AnswerChoice.B,
140140
);
141141
}
142142

@@ -150,7 +150,7 @@ export class Lesson5 {
150150
[AnswerChoice.C, "inline-block"],
151151
[AnswerChoice.D, "none"],
152152
]),
153-
AnswerChoice.UNANSWERED,
153+
AnswerChoice.B,
154154
);
155155
}
156156

@@ -164,11 +164,13 @@ export class Lesson5 {
164164
[AnswerChoice.C, "<stylesheet link='styles.css'>"],
165165
[AnswerChoice.D, "<css href='styles.css'>"],
166166
]),
167-
AnswerChoice.UNANSWERED,
167+
AnswerChoice.A,
168168
);
169169
}
170170
}
171171

172172
if (!process.env.JEST_WORKER_ID) {
173173
new Lesson5().run();
174174
}
175+
176+

lesson_07/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Please review the following resources before lecture:
1818
This exercise will provide you ample opportunities to practice your understanding of conditional expressions and loops. To complete this assignment, implement the functions in [lesson7.ts][lesson7-file] and in the code file for your assigned homework group, ensure the tests pass, and submit a PR. Remember to use the [Conventional Commits][conventional-commits] spec for your commit messages and pull requests.
1919

2020
[lesson7-file]: ./conditionals/src/lesson7.ts
21-
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/
21+
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/
22+

lesson_07/conditionals/src/lesson7.ts

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

2026
/**
@@ -24,9 +30,17 @@ export function compareStrings(a: string, b: string): number {
2430
* @return The factorial of n.
2531
*/
2632
export function computeFactorial(n: number): number {
27-
return 0;
33+
if (n ===0 || n===1) {
34+
return 1
35+
}
36+
else {
37+
return n * computeFactorial(n-1);
38+
}
2839
}
2940

41+
42+
43+
3044
/**
3145
* Returns an array of the first `n` Fibonacci numbers starting from 1.
3246
*
@@ -35,7 +49,24 @@ export function computeFactorial(n: number): number {
3549
*/
3650
export function getFirstNFibonacciNumbers(n: number): number[] {
3751
return [];
38-
}
52+
if (n===0) {
53+
return[];
54+
55+
else if (n=== 1) {
56+
return [1];
57+
}
58+
else if (n===2) {
59+
return [1,1];
60+
}
61+
else{
62+
const fib =getFirstNFibonacciNumbers(n -1);
63+
fib.push(fib[fib.length - 1] + fib [fib.length - 2]);
64+
return fib;
65+
}
66+
}
67+
68+
}
69+
3970

4071
/**
4172
* Finds a value in an array of values.
@@ -59,7 +90,19 @@ export function binarySearch(
5990

6091
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.
6192

62-
// TODO(you): Finish implementing this algorithm
93+
if (values[pivotIndex] === value) {
94+
return pivotIndex;
95+
} else if (values[pivotIndex] > value) {
96+
return binarySearch( values, start, pivotIndex -1, value);
97+
else { binarySearch(values, start, pivotIndex - 1, value)}
98+
return value;
99+
100+
else {
101+
102+
return
103+
binarySearch(values, pivotIndex + 1, end, value)
104+
}
105+
}
63106

64107
// If values[pivotIndex] is equal to value then return `pivotIndex`.
65108
// Else if values[pivotIndex] is greater than the value, then

lesson_07/conditionals/src/part_a.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
* @return True if the age corresponds to a voting age and false otherwise.
66
*/
77
export function canVote(age: number): boolean {
8-
return false;
8+
if (age >= 18) {
9+
return true;
10+
}
11+
12+
else {
13+
return false;
14+
}
915
}
16+
console.log(canVote(18))
1017

1118
/**
1219
* Adds all of the provided values and returns the sum.
@@ -15,15 +22,35 @@ export function canVote(age: number): boolean {
1522
* @return The sum of all the values.
1623
*/
1724
export function addNumbers(values: number[]): number {
25+
26+
27+
for (let i = 0; i < values.length ; i++) {
28+
29+
30+
return values[i];
31+
}
32+
33+
1834
return 0;
1935
}
2036

37+
2138
/**
2239
* Computes the factorial of the given value of `n`.
2340
*
2441
* @param n The value for which to compute the factorial.
2542
* @return The factorial of n.
2643
*/
2744
export function computeFactorial(n: number): number {
45+
46+
if (n <0 ){
47+
48+
return 0;
49+
}
50+
51+
let factorial = 1
52+
53+
2854
return 0;
2955
}
56+

0 commit comments

Comments
 (0)