Skip to content

Commit b1c39a7

Browse files
committed
Fix incorrect GPA conversion when grade is F
Signed-off-by: Gary Kim <[email protected]>
1 parent c6a6d16 commit b1c39a7

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/js/__tests__/parsers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ test('Grade to GPA without Weighting', t => {
101101
{
102102
i: "P",
103103
o: -1
104+
},
105+
{
106+
i: "",
107+
o: -1
108+
},
109+
{
110+
i: "asdjfh",
111+
o: -1
112+
},
113+
{
114+
i: 182.2,
115+
o: -1
104116
}
105117
];
106118

@@ -152,6 +164,18 @@ test('Grade to Final Percent', t => {
152164
{
153165
i: "P",
154166
o: -1
167+
},
168+
{
169+
i: "",
170+
o: -1
171+
},
172+
{
173+
i: "asdjfh",
174+
o: -1
175+
},
176+
{
177+
i: 182.2,
178+
o: -1
155179
}
156180
];
157181

src/js/helpers.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ const grade_gpa = {
4141
* @param {string} grade The grade to convert.
4242
* @returns {number} The corresponding grade point average.
4343
*/
44-
const gradeToGPA = grade => grade_gpa[grade] || -1;
44+
function gradeToGPA(grade) {
45+
if (grade in grade_gpa) {
46+
return grade_gpa[grade];
47+
}
48+
return -1;
49+
}
4550

4651
const grade_fp = {
4752
'A+': 90,
@@ -60,7 +65,12 @@ const grade_fp = {
6065
* @param {string} grade The grade to convert.
6166
* @returns {number} The corresponding final percent.
6267
*/
63-
const gradeToFP = grade => grade_fp[grade] || -1;
68+
function gradeToFP(grade) {
69+
if (grade in grade_fp) {
70+
return grade_fp[grade];
71+
}
72+
return -1;
73+
}
6474

6575
const avaliableGrades = ["A+", "A", "B+", "B", "C+", "C", "D+", "D", "F"];
6676

0 commit comments

Comments
 (0)