Skip to content

Commit

Permalink
Merge pull request #779 from sandboxnu/course-crash-bug
Browse files Browse the repository at this point in the history
Course crash bug
  • Loading branch information
ShireenKumar authored Dec 3, 2024
2 parents b690d5d + 38fe9ee commit d3d7d58
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/frontend/utils/plan/getAllCoursesInMajor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getAllCoursesInMajor = (
const majorRequirements = major.requirementSections.reduce(
(courses: IRequiredCourse[], section: Section) => {
const requiredCourses: IRequiredCourse[] = [];
getRequiredCourses(section.requirements, requiredCourses);
getRequiredCourses(section.requirements ?? [], requiredCourses);
return courses.concat(requiredCourses);
},
[]
Expand Down Expand Up @@ -54,9 +54,19 @@ const getRequiredCourses = (
} else if (requirement.type === "COURSE") {
requiredCourses.push(requirement);
} else if (requirement.type === "SECTION") {
getRequiredCourses(requirement.requirements, requiredCourses);
getRequiredCourses(requirement.requirements ?? [], requiredCourses);
} else if (Array.isArray(requirement)) {
getRequiredCourses(extractRequirements(requirement), requiredCourses);
} else {
getRequiredCourses(requirement.courses, requiredCourses);
getRequiredCourses(requirement.courses ?? [], requiredCourses);
}
}
};

const extractRequirements = (requirements: Requirement2[]): Requirement2[] => {
const extracted: Requirement2[] = [];
for (const value of requirements) {
extracted.push(value);
}
return extracted;
};

0 comments on commit d3d7d58

Please sign in to comment.