Skip to content

Commit

Permalink
Merge pull request #786 from sandboxnu/major-algorithm-patch
Browse files Browse the repository at this point in the history
Major Algorithm Patch
  • Loading branch information
KobeZ123 authored Dec 5, 2024
2 parents 2699689 + b6a611f commit 8b6a4a0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/common/src/major2-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ function validateSectionRequirement(
tracker: CourseValidationTracker
): Result<Array<Solution>, MajorValidationError> {
if (r.minRequirementCount < 1) {
return Ok([]);
// this should be an invalid shape and throw an error, but for now we'll just return an empty array
// since the solution for a section with no requirements is an empty array
throw new Error("Section requirement count must be >= 1");
}

Expand Down Expand Up @@ -732,5 +735,25 @@ function validateRequirements(
rs: Requirement2[],
tracker: CourseValidationTracker
) {
while (rs.some((r) => Array.isArray(r))) {
const newRs = [];
for (const r of rs) {
if (Array.isArray(r)) {
newRs.push(...extractRequirements(r));
} else {
newRs.push(r);
}
}
rs = newRs;
}

return rs.map((r) => validateRequirement(r, tracker));
}

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

0 comments on commit 8b6a4a0

Please sign in to comment.