[+] Create method to calculate GP for a course
This commit is contained in:
+26
-1
@@ -31,7 +31,7 @@ export class GPAUtils
|
|||||||
*
|
*
|
||||||
* @param coursesOriginal List of courses
|
* @param coursesOriginal List of courses
|
||||||
*/
|
*/
|
||||||
public static gpa(coursesOriginal: Course[]): {gpa: number, accurate: boolean}
|
public static getGPA(coursesOriginal: Course[]): {gpa: number, accurate: boolean}
|
||||||
{
|
{
|
||||||
// Clone array
|
// Clone array
|
||||||
let courses: Course[] = [];
|
let courses: Course[] = [];
|
||||||
@@ -84,4 +84,29 @@ export class GPAUtils
|
|||||||
// Get average GPA
|
// Get average GPA
|
||||||
return {gpa: totalGPA / courses.length, accurate: accurate};
|
return {gpa: totalGPA / courses.length, accurate: accurate};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate GPA for a course
|
||||||
|
*
|
||||||
|
* @param course Course
|
||||||
|
*/
|
||||||
|
public static getGP(course: Course)
|
||||||
|
{
|
||||||
|
// Find the GPA for this course.
|
||||||
|
return this.SCALE.forEach(scale =>
|
||||||
|
{
|
||||||
|
// Letter grades are the same
|
||||||
|
if (scale[this.LETTER] == course.letterGrade)
|
||||||
|
{
|
||||||
|
// Get grade and add it
|
||||||
|
let grade = <number> scale[this.GPA];
|
||||||
|
|
||||||
|
// Add scaleUp if not failed.
|
||||||
|
if (grade != 0) grade += course.scaleUp;
|
||||||
|
|
||||||
|
// That's it
|
||||||
|
return grade;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user