@@ -42,27 +42,25 @@ export function compareStrings(a: string, b: string): number {
42
42
*/
43
43
export function convertGpaToLetterGrade ( gpa : number ) : string {
44
44
switch ( true ) {
45
- case gpa >= 97 :
46
- return "A+" ;
47
- case gpa >= 93 && gpa <= 96 :
45
+ case gpa >= 4.0 :
48
46
return "A" ;
49
- case gpa >= 90 && gpa <= 92 :
47
+ case gpa >= 3.7 && gpa <= 3.99 :
50
48
return "A-" ;
51
- case gpa >= 87 && gpa <= 89 :
49
+ case gpa >= 3.3 && gpa <= 3.69 :
52
50
return "B+" ;
53
- case gpa >= 83 && gpa <= 86 :
51
+ case gpa >= 3 && gpa <= 3.29 :
54
52
return "B" ;
55
- case gpa >= 80 && gpa <= 82 :
53
+ case gpa >= 2.7 && gpa <= 2.99 :
56
54
return "B-" ;
57
- case gpa >= 77 && gpa <= 79 :
55
+ case gpa >= 2.3 && gpa <= 2.69 :
58
56
return "C+" ;
59
- case gpa >= 73 && gpa <= 76 :
57
+ case gpa >= 2 && gpa <= 2.29 :
60
58
return "C" ;
61
- case gpa >= 70 && gpa <= 72 :
59
+ case gpa >= 1.7 && gpa <= 1.99 :
62
60
return "C-" ;
63
- case gpa >= 67 && gpa <= 69 :
61
+ case gpa >= 1.3 && gpa <= 1. 69 :
64
62
return "D+" ;
65
- case gpa >= 65 && gpa <= 66 :
63
+ case gpa >= 1 && gpa <= 1.29 :
66
64
return "D" ;
67
65
default :
68
66
return "F" ;
@@ -113,23 +111,10 @@ export function addNumbers(values: number[]): number {
113
111
* @return An array containing the first n Fibonacci values.
114
112
*/
115
113
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
130
115
131
116
// 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 ++ ) {
133
118
const Fibonacci = array [ i - 1 ] + array [ i - 2 ] ; //add the numbers 2 positions behind to get current position
134
119
array . push ( Fibonacci ) ;
135
120
}
@@ -165,10 +150,8 @@ export function binarySearch(
165
150
// Else if values[pivotIndex] is greater than the value, then
166
151
// call binarySearch(values, start, pivotIndex - 1, value) and return its value;
167
152
// 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 ;
169
154
else if ( values [ pivotIndex ] > pivotIndex )
170
155
return binarySearch ( values , start , pivotIndex - 1 , value ) ;
171
156
else return binarySearch ( values , pivotIndex + 1 , end , value ) ;
172
-
173
- return - 1 ;
174
157
}
0 commit comments