@@ -7,6 +7,9 @@ import { computeLexicographicDistance } from "./util.js";
7
7
* @return True if the age corresponds to a voting age and false otherwise.
8
8
*/
9
9
export function canVote ( age : number ) : boolean {
10
+ if ( age >= 18 ) {
11
+ return true ;
12
+ }
10
13
return false ;
11
14
}
12
15
@@ -22,6 +25,12 @@ export function compareStrings(a: string, b: string): number {
22
25
// if it is greater, and 0 if the strings are equal.
23
26
const distance = computeLexicographicDistance ( a , b ) ;
24
27
28
+ if ( distance < 0 ) {
29
+ // instructions say 'distance will be A NUMBER less than 0 ' not quite exactly -1
30
+ return - 1 ;
31
+ }
32
+
33
+ return distance ; // instructions clearly state will be 0 if a === b and 1 if a > b which is what we want
25
34
// TODO(you): Finish this method.
26
35
27
36
return 0 ;
@@ -37,7 +46,35 @@ export function compareStrings(a: string, b: string): number {
37
46
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
38
47
*/
39
48
export function convertGpaToLetterGrade ( gpa : number ) : string {
40
- return "F" ;
49
+ switch (
50
+ true // better way to do this. want to use the equivilent of a Java Map (XavierCruz5106)
51
+ ) {
52
+ case gpa >= 1.0 && gpa < 1.3 :
53
+ return "D" ;
54
+ case gpa >= 1.3 && gpa < 1.7 :
55
+ return "D+" ;
56
+ case gpa >= 1.7 && gpa < 2.0 :
57
+ return "C-" ;
58
+ case gpa >= 2.0 && gpa < 2.3 :
59
+ return "C" ;
60
+ case gpa >= 2.3 && gpa < 2.7 :
61
+ return "C+" ;
62
+ case gpa >= 2.7 && gpa < 3.0 :
63
+ return "B-" ;
64
+ case gpa >= 3.0 && gpa < 3.3 :
65
+ return "B" ;
66
+ case gpa >= 3.3 && gpa < 3.7 :
67
+ return "B+" ;
68
+ case gpa >= 3.7 && gpa < 3.9 :
69
+ return "A-" ;
70
+ case gpa === 3.9 :
71
+ return "A" ;
72
+ case gpa === 4.0 :
73
+ return "A+" ;
74
+
75
+ default :
76
+ return "F" ;
77
+ }
41
78
}
42
79
43
80
/**
@@ -47,7 +84,12 @@ export function convertGpaToLetterGrade(gpa: number): string {
47
84
* @return The factorial of n.
48
85
*/
49
86
export function computeFactorial ( n : number ) : number {
50
- return 0 ;
87
+ let total = 1 ;
88
+ for ( let i = 2 ; i <= n ; i ++ ) {
89
+ total *= i ;
90
+ }
91
+
92
+ return total ;
51
93
}
52
94
53
95
/**
@@ -57,7 +99,11 @@ export function computeFactorial(n: number): number {
57
99
* @return The sum of all the values.
58
100
*/
59
101
export function addNumbers ( values : number [ ] ) : number {
60
- return 0 ;
102
+ let sum = 0 ;
103
+ for ( const value in values ) {
104
+ sum += Number ( value ) ;
105
+ }
106
+ return sum ;
61
107
}
62
108
63
109
/**
@@ -67,6 +113,14 @@ export function addNumbers(values: number[]): number {
67
113
* @return An array containing the first `n` Fibonacci values.
68
114
*/
69
115
export function getFirstNFibonacciNumbers ( n : number ) : number [ ] {
116
+ const nums = [ ] ;
117
+ let prev = 0 ;
118
+ for ( let i = 1 ; i < n ; i ++ ) {
119
+ const next = i + prev ;
120
+ prev = i ;
121
+
122
+ console . log ( next ) ;
123
+ }
70
124
return [ ] ;
71
125
}
72
126
0 commit comments