@@ -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
/**
@@ -18,13 +22,19 @@ export function canVote(age: number): boolean {
18
22
* @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise.
19
23
*/
20
24
export function compareStrings ( a : string , b : string ) : number {
25
+ const distance = computeLexicographicDistance ( a , b ) ;
26
+
27
+ if ( a > b ) {
28
+ return - 1 ;
29
+ } else if ( b > a ) {
30
+ return 1 ;
31
+ } else {
32
+ return 0 ;
33
+ }
21
34
// The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1
22
35
// if it is greater, and 0 if the strings are equal.
23
- const distance = computeLexicographicDistance ( a , b ) ;
24
36
25
37
// TODO(you): Finish this method.
26
-
27
- return 0 ;
28
38
}
29
39
30
40
/**
@@ -37,7 +47,31 @@ export function compareStrings(a: string, b: string): number {
37
47
* @return The letter grade ("A+", "A", "A-", "B+", etc.).
38
48
*/
39
49
export function convertGpaToLetterGrade ( gpa : number ) : string {
40
- return "F" ;
50
+ if ( gpa < 0 || gpa > 4.0 ) {
51
+ return "Invaild GPA" ;
52
+ } else if ( gpa <= 0.9 ) {
53
+ return "F" ;
54
+ } else if ( gpa < 1.25 && gpa >= 1.0 ) {
55
+ return "D" ;
56
+ } else if ( gpa < 1.75 && gpa >= 1.25 ) {
57
+ return "D+" ;
58
+ } else if ( gpa < 2.0 && gpa >= 1.75 ) {
59
+ return "C-" ;
60
+ } else if ( gpa < 2.3 && gpa >= 2.0 ) {
61
+ return "C" ;
62
+ } else if ( gpa < 2.7 && gpa >= 2.3 ) {
63
+ return "C+" ;
64
+ } else if ( gpa < 3.0 && gpa >= 2.7 ) {
65
+ return "B-" ;
66
+ } else if ( gpa < 3.3 && gpa >= 3.0 ) {
67
+ return "B" ;
68
+ } else if ( gpa < 3.7 && gpa >= 3.3 ) {
69
+ return "B+" ;
70
+ } else if ( gpa < 4.0 && gpa >= 3.7 ) {
71
+ return "A" ;
72
+ } else {
73
+ return "A+" ;
74
+ }
41
75
}
42
76
43
77
/**
@@ -47,9 +81,12 @@ export function convertGpaToLetterGrade(gpa: number): string {
47
81
* @return The factorial of n.
48
82
*/
49
83
export function computeFactorial ( n : number ) : number {
50
- return 0 ;
84
+ let sum = 1 ;
85
+ for ( let i = 1 ; 1 <= n ; i ++ ) {
86
+ sum = sum *= i ;
87
+ }
88
+ return sum ;
51
89
}
52
-
53
90
/**
54
91
* Adds all of the provided values and returns the sum.
55
92
*
0 commit comments