@@ -7,7 +7,11 @@ 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
- return false ;
10
+ if ( age >= 18 ) {
11
+ return true ;
12
+ } else {
13
+ return false ;
14
+ }
11
15
}
12
16
13
17
/**
@@ -23,10 +27,12 @@ export function compareStrings(a: string, b: string): number {
23
27
const distance = computeLexicographicDistance ( a , b ) ;
24
28
25
29
// TODO(you): Finish this method.
30
+ if ( distance < 0 ) {
31
+ return - 1 ;
32
+ }
26
33
27
- return 0 ;
34
+ return distance ;
28
35
}
29
-
30
36
/**
31
37
* Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board
32
38
* scale. See
@@ -37,17 +43,46 @@ export function compareStrings(a: string, b: string): number {
37
43
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
38
44
*/
39
45
export function convertGpaToLetterGrade ( gpa : number ) : string {
40
- return "F" ;
46
+ if ( gpa == 4.0 ) {
47
+ return "A" ;
48
+ } else if ( gpa > 4.0 ) {
49
+ return "A" ;
50
+ } else if ( gpa <= 3.99 && gpa >= 3.7 ) {
51
+ return "A-" ;
52
+ } else if ( gpa <= 3.69 && gpa >= 3.3 ) {
53
+ return "B+" ;
54
+ } else if ( gpa <= 3.29 && gpa >= 3.0 ) {
55
+ return "B" ;
56
+ } else if ( gpa <= 2.99 && gpa >= 2.7 ) {
57
+ return "B-" ;
58
+ } else if ( gpa <= 2.69 && gpa >= 2.3 ) {
59
+ return "C+" ;
60
+ } else if ( gpa <= 2.29 && gpa >= 2.0 ) {
61
+ return "C" ;
62
+ } else if ( gpa <= 1.99 && gpa >= 1.7 ) {
63
+ return "C-" ;
64
+ } else if ( gpa <= 1.69 && gpa >= 1.3 ) {
65
+ return "D+" ;
66
+ } else if ( gpa <= 1.29 && gpa >= 1.0 ) {
67
+ return "D" ;
68
+ } else {
69
+ return "F" ;
70
+ }
41
71
}
42
72
43
- /**
44
- * Computes the factorial of the given value of `n`.
73
+ /**km
74
+ * computes the factorial of the given value of `n`.
45
75
*
46
76
* @param n The value for which to compute the factorial.
47
77
* @return The factorial of n.
48
78
*/
49
79
export function computeFactorial ( n : number ) : number {
50
- return 0 ;
80
+ let product = 1 ;
81
+ for ( let i = 1 ; 1 <= n ; i ++ ) {
82
+ product *= i ;
83
+ }
84
+
85
+ return product ;
51
86
}
52
87
53
88
/**
@@ -57,7 +92,12 @@ export function computeFactorial(n: number): number {
57
92
* @return The sum of all the values.
58
93
*/
59
94
export function addNumbers ( values : number [ ] ) : number {
60
- return 0 ;
95
+ let sum = 0 ; //initialize variable
96
+
97
+ for ( const value of values ) {
98
+ sum += value ; //adds value to each
99
+ }
100
+ return sum ;
61
101
}
62
102
63
103
/**
0 commit comments