Skip to content

Commit b437a7d

Browse files
committed
fix: lesson_07 changes to fibbonacci and binarysearch question
1 parent 20c7b3e commit b437a7d

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,25 @@ export function compareStrings(a: string, b: string): number {
4242
*/
4343
export function convertGpaToLetterGrade(gpa: number): string {
4444
switch (true) {
45-
case gpa >= 97:
46-
return "A+";
47-
case gpa >= 93 && gpa <= 96:
45+
case gpa >= 4.0:
4846
return "A";
49-
case gpa >= 90 && gpa <= 92:
47+
case gpa >= 3.7 && gpa <= 3.99:
5048
return "A-";
51-
case gpa >= 87 && gpa <= 89:
49+
case gpa >= 3.3 && gpa <= 3.69:
5250
return "B+";
53-
case gpa >= 83 && gpa <= 86:
51+
case gpa >= 3 && gpa <= 3.29:
5452
return "B";
55-
case gpa >= 80 && gpa <= 82:
53+
case gpa >= 2.7 && gpa <= 2.99:
5654
return "B-";
57-
case gpa >= 77 && gpa <= 79:
55+
case gpa >= 2.3 && gpa <= 2.69:
5856
return "C+";
59-
case gpa >= 73 && gpa <= 76:
57+
case gpa >= 2 && gpa <= 2.29:
6058
return "C";
61-
case gpa >= 70 && gpa <= 72:
59+
case gpa >= 1.7 && gpa <= 1.99:
6260
return "C-";
63-
case gpa >= 67 && gpa <= 69:
61+
case gpa >= 1.3 && gpa <= 1.69:
6462
return "D+";
65-
case gpa >= 65 && gpa <= 66:
63+
case gpa >= 1 && gpa <= 1.29:
6664
return "D";
6765
default:
6866
return "F";
@@ -113,23 +111,10 @@ export function addNumbers(values: number[]): number {
113111
* @return An array containing the first n Fibonacci values.
114112
*/
115113
export function getFirstNFibonacciNumbers(n: number): number[] {
116-
const array: number[] = []; // takes number and converts to array
117-
if (n === 0) {
118-
// base case for array 0
119-
array.push(0);
120-
return array;
121-
}
122-
if (n === 1) {
123-
// base case for array 1
124-
array.push(0);
125-
array.push(1);
126-
return array;
127-
}
128-
array.push(0);
129-
array.push(1);
114+
const array = [0, 1]; //populate array with 0,1 for base cases
130115

131116
// starting at 2 increment i until it is = n
132-
for (let i = 2; i <= n; i++) {
117+
for (let i = 2; i < n; i++) {
133118
const Fibonacci = array[i - 1] + array[i - 2]; //add the numbers 2 positions behind to get current position
134119
array.push(Fibonacci);
135120
}
@@ -165,10 +150,8 @@ export function binarySearch(
165150
// Else if values[pivotIndex] is greater than the value, then
166151
// call binarySearch(values, start, pivotIndex - 1, value) and return its value;
167152
// Else call binarySearch(values, pivotIndex + 1, end, value) and return its value.
168-
if (values[pivotIndex] === pivotIndex) return pivotIndex;
153+
if (values[pivotIndex] === value) return pivotIndex;
169154
else if (values[pivotIndex] > pivotIndex)
170155
return binarySearch(values, start, pivotIndex - 1, value);
171156
else return binarySearch(values, pivotIndex + 1, end, value);
172-
173-
return -1;
174157
}

0 commit comments

Comments
 (0)