Skip to content

Commit

Permalink
Created helper function to deal with nested arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ShireenKumar committed Nov 21, 2024
1 parent 0dcd9c5 commit 38fe9ee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,48 +285,50 @@
"type": "XOM",
"numCreditsMin": 12,
"courses": [
{
"type": "RANGE",
"subject": "ARTD",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTE",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTF",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTG",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTH",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "GAME",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
[
{
"type": "RANGE",
"subject": "ARTD",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTE",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTF",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTG",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "ARTH",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
},
{
"type": "RANGE",
"subject": "GAME",
"idRangeStart": 0,
"idRangeEnd": 9999,
"exceptions": []
}
],
{
"type": "RANGE",
"subject": "CS",
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/utils/plan/getAllCoursesInMajor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ const getRequiredCourses = (
requiredCourses.push(requirement);
} else if (requirement.type === "SECTION") {
getRequiredCourses(requirement.requirements ?? [], requiredCourses);
} else if (Array.isArray(requirement)) {
getRequiredCourses(extractRequirements(requirement), requiredCourses);
} else {
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 38fe9ee

Please sign in to comment.