Skip to content

Commit e5488bb

Browse files
committed
chore: cleaned up notes for Kimberlee's lesson_07
conditionals
1 parent e3bdffd commit e5488bb

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ export function compareStrings(a: string, b: string): number {
3434
}
3535

3636
export function computeLexicographicDistance(a: string, b: string): number {
37-
//I literally used export function again because typescript kept telling me
38-
// that my return statements needed to be inside the body of a function.
39-
// I'm a bit skeptical because we are supposed to be DRY! and the only thing I
40-
// changed was the function name. But it worked. I'm just leaving this note
41-
// to remind myself to ask for clarification about this.
37+
4238
if (a < b) {
4339
return -1;
4440
} else if (a > b) {
@@ -51,14 +47,7 @@ export function computeLexicographicDistance(a: string, b: string): number {
5147
const result = compareStrings("Kimberlee", "haldane");
5248
console.log(result);
5349

54-
//If I am understanding question 2 correctly, because the first function
55-
// 'compareStrings' calls on a second function 'computeLexicographicDistance',
56-
// I needed to set up both functions. The first function calls the second
57-
// and the second function does the actual calculation and determines if each string
58-
// is one of this set (-1, 1, 0). Testing is when the first function comes
59-
//back into play, comparing two strings and returning a numerical result. Sorry
60-
// for the long note, it took me a VERY long time to get to this understanding.
61-
// I just hope I am right.
50+
6251

6352
/** (Q3)
6453
* Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board
@@ -74,7 +63,6 @@ export function myGrade(grade: number): string {
7463
return gpa;
7564
}
7665

77-
//I followed the same logic as question 2.
7866

7967
export function convertGpaToLetterGrade(gpa: number): string {
8068
if (gpa >= 4.0) {
@@ -116,12 +104,12 @@ console.log(grade);
116104
export function computeFactorial(n: number): number {
117105
let result = 1;
118106
for (let i = 1; i <= n; i++) {
119-
// I used i+1 and fell into an infinite loop. My bad!
107+
120108
result *= i;
121109
}
122110
return result;
123111
}
124-
// Steps I followed: Describe the function, Declare the function, crawl inside the function
112+
125113
const n = 7;
126114
console.log(computeFactorial(n));
127115

@@ -149,26 +137,18 @@ console.log(sum);
149137
* @param n The first `n` of Fibonacci values to compute.
150138
* @return An array containing the first `n` Fibonacci values.
151139
*/
152-
//This question nearly had me in tears and I'm sad to say that in the end
153-
// I had to seek help. However, I think if I can explain what I learned as
154-
// I go, that help would not have been in vain. Again, pardon the long notes.
140+
155141
export function getFirstNFibonacciNumbers(n: number): number[] {
156-
const myArray: number[] = []; // First: initiatialize an empty array inside the function
157-
// Next:Take care of base case since the first two Fibonacci numbers are 1, 1.
158-
// If n is 1, return an array with the first number. If n is 2, return an array with
159-
// the first two numbers. This step is crucial for ensuring the loop works properly.
142+
const myArray: number[] = [];
160143
if (n <= 0) return [];
161144
if (n === 1) return [1];
162145
if (n === 2) return [1, 1];
163146
myArray.push(1, 1);
164147

165148
for (let i = 2; i < n; i++) {
166-
//initialization(starts at 2 because I added the first two numbers in the sequence above)
167-
// so this tells the function to start computing from the 3rd number. Condition: this tells
168-
// the function that it can only work with numbers less than the given number.
169-
// Increment: this tells the function to move on to the next number by 1 (no infinite loops).
149+
170150
const nextNum = myArray[i - 1] + myArray[i - 2];
171-
myArray.push(nextNum); // adds the new number to the array to continue the loop
151+
myArray.push(nextNum);
172152
}
173153
return myArray;
174154
}
@@ -191,11 +171,11 @@ export function binarySearch(
191171
value: number,
192172
): number {
193173
if (end < start) {
194-
// The range is not valid so just return -1.
174+
195175
return -1;
196176
}
197177

198-
const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array.
178+
const pivotIndex = Math.floor((start + end) / 2);
199179

200180
if (values[pivotIndex] === value) {
201181
return pivotIndex;
@@ -204,7 +184,7 @@ export function binarySearch(
204184
}
205185
return binarySearch(values, pivotIndex + 1, end, value);
206186
}
207-
// This problem was much easier to write out because of question 6.
187+
208188
const values = [ 2, 4, 6, 8, 10, 12, 14, 16];
209189
const index = binarySearch(values, 4, 8, 14);
210190
console.log(index);

0 commit comments

Comments
 (0)