@@ -7,7 +7,11 @@ import { computeLexicographicDistance } from "./util.js";
77 * @return True if the age corresponds to a voting age and false otherwise.
88 */
99export function canVote ( age : number ) : boolean {
10- return false ;
10+ if ( age >= 18 ) {
11+ return true ;
12+ } else {
13+ return false ;
14+ }
1115}
1216
1317/**
@@ -23,10 +27,12 @@ export function compareStrings(a: string, b: string): number {
2327 const distance = computeLexicographicDistance ( a , b ) ;
2428
2529 // TODO(you): Finish this method.
30+ if ( distance < 0 ) {
31+ return - 1 ;
32+ }
2633
27- return 0 ;
34+ return distance ;
2835}
29-
3036/**
3137 * Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board
3238 * scale. See
@@ -37,17 +43,46 @@ export function compareStrings(a: string, b: string): number {
3743 * @return The letter grade ("A+", "A", "A-", "B+", etc.).
3844 */
3945export 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+ }
4171}
4272
43- /**
44- * Computes the factorial of the given value of `n`.
73+ /**km
74+ * computes the factorial of the given value of `n`.
4575 *
4676 * @param n The value for which to compute the factorial.
4777 * @return The factorial of n.
4878 */
4979export 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 ;
5186}
5287
5388/**
@@ -57,7 +92,12 @@ export function computeFactorial(n: number): number {
5792 * @return The sum of all the values.
5893 */
5994export 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 ;
61101}
62102
63103/**
0 commit comments