refactor: Update getCreditHours function to handle additional cases (#222)

* refactor: Update getCreditHours function to handle additional cases

* style: fix prettier
This commit is contained in:
Razboy20
2024-05-21 20:59:08 -05:00
committed by GitHub
parent 6812d685d0
commit 2f9e9b1297

View File

@@ -122,11 +122,27 @@ export class CourseCatalogScraper {
/**
* Gets how many credit hours the course is worth
* @param number the course number, CS 314H
* @param courseNumber the course number, CS 314H
* @return the number of credit hours the course is worth
*/
getCreditHours(number: string): number {
return Number(number.split('')[0]);
getCreditHours(courseNumber: string): number {
let creditHours = Number(courseNumber.split('')[0]);
const lastChar = courseNumber.slice(-1);
// eslint-disable-next-line default-case
switch (lastChar) {
case 'A':
case 'B':
creditHours /= 2;
break;
case 'X':
case 'Y':
case 'Z':
creditHours /= 3;
break;
}
return creditHours;
}
/**