Created
March 1, 2025 11:47
-
-
Save faresbakhit/d537dd7387313e1d1254af2c4fe0ad37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* Examples: | |
* | |
* // Calculate GPA using grades from the current page | |
* const gpa1 = newecomComputeGPA(); | |
* | |
* // Calculate GPA with modified grades for MA112 and HU118, and removing CS112 | |
* const gpa2 = newecomComputeGPA({ "MA112": "A+", "HU118": "B+", "CS112": "" }); | |
* | |
*/ | |
const newecomComputeGPA = (courseGradeReplacements = {}) => { | |
const grades = { 'A+': 4.0, 'A': 3.7, 'A-': 3.4, | |
'B+': 3.2, 'B': 3.0, 'B-': 2.8, | |
'C+': 2.6, 'C': 2.4, 'C-': 2.2, | |
'D+': 2.0, 'D': 1.5, 'D-': 1.0, 'F': 0 }; | |
let total_credit_hours = 0; | |
return [...document.querySelectorAll('tbody').item(1).children].reduce((acc, tr) => { | |
let credit_hours = Number.parseInt(tr.children[3].innerText); | |
let course_grade = courseGradeReplacements[tr.children[0].innerText]; | |
if (course_grade === undefined) { | |
course_grade = tr.children[6].innerText; | |
} | |
let grade_points = grades[course_grade]; | |
if (!isNaN(credit_hours) && grade_points !== undefined) { | |
total_credit_hours += credit_hours; | |
return acc + grade_points * credit_hours; | |
} | |
return acc; | |
}, 0) / total_credit_hours; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment