Skip to content

Commit e5007e4

Browse files
author
“A1-4U2T1NN”
committed
fix: converted 'if' statements into 'else if' statements l.53-71; removed 'return array' if 'n = 0'; corrected formatting on binarySearch
;
1 parent 962d2dc commit e5007e4

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lesson_07/conditionals/src/lesson7.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,29 @@ export function compareStrings(a: string, b: string): number {
4747
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
4848
*/
4949
export function convertGpaToLetterGrade(gpa: number): string {
50+
5051
if(gpa >= 97){
5152
return "A+"
52-
}if(gpa >= 93){
53+
}else if(gpa >= 93){
5354
return "A"
54-
}if(gpa >= 90){
55+
}else if(gpa >= 90){
5556
return "A-"
56-
}if(gpa >= 87){
57+
}else if(gpa >= 87){
5758
return "B+"
58-
}if(gpa >= 83){
59+
}else if(gpa >= 83){
5960
return "B"
60-
}if(gpa >= 80){
61+
}else if(gpa >= 80){
6162
return "B-"
62-
}if(gpa >= 77){
63+
}else if(gpa >= 77){
6364
return "C+"
64-
}if(gpa >= 73){
65+
}else if(gpa >= 73){
6566
return "C"
66-
}if(gpa >= 70){
67+
}else if(gpa >= 70){
6768
return "C-";
68-
}if(gpa >= 67){
69+
}else if(gpa >= 67){
6970
return "D+";
70-
}if(gpa >= 65){
71-
return "D-";
71+
}else if(gpa >= 65){
72+
return "D";
7273
}else{
7374
return "F"
7475
}
@@ -81,7 +82,9 @@ export function convertGpaToLetterGrade(gpa: number): string {
8182
* @return The factorial of n.
8283
*/
8384
export function computeFactorial(n: number): number {
85+
8486
let totalValue = 1
87+
8588
for(let i = 1; n >= i; i++){
8689
totalValue *= i
8790
}
@@ -112,12 +115,9 @@ export function addNumbers(values: number[]): number {
112115
* @return An array containing the first `n` Fibonacci values.
113116
*/
114117
export function getFirstNFibonacciNumbers(n: number): number[] {
118+
115119
const array = [n]
116120

117-
if(n <= 0){
118-
return array;
119-
}
120-
121121
for(let i = 2; i < n; i++){
122122
const cont = array[i - 1] + array[i - 2];
123123
array.push(cont)
@@ -150,10 +150,10 @@ export function binarySearch(
150150
// TODO(you): Finish implementing this algorithm
151151
if (values[pivotIndex] === value){
152152
return pivotIndex;
153-
} if (values[pivotIndex] < value){
153+
} if (values[pivotIndex] > value){
154154
return binarySearch(values, start, pivotIndex - 1, value);
155155
} else {
156-
return binarySearch(values, pivotIndex - 1, end, value);
156+
return binarySearch(values, pivotIndex + 1, end, value);
157157
}
158158
// If values[pivotIndex] is equal to value then return `pivotIndex`.
159159
// Else if values[pivotIndex] is greater than the value, then

0 commit comments

Comments
 (0)