Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mhd-hi committed Nov 29, 2024
1 parent d767185 commit 0315767
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/common/utils/course-instance/courseInstanceUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ export class AvailabilityUtil {
): boolean {
if (a.length !== b.length) return false;

const sortedA = [...a].sort();
const sortedB = [...b].sort();
const frequencyMapA = AvailabilityUtil.buildFrequencyMap(a);
const frequencyMapB = AvailabilityUtil.buildFrequencyMap(b);

for (let i = 0; i < sortedA.length; i++) {
if (sortedA[i] !== sortedB[i]) {
for (const [availability, count] of frequencyMapA.entries()) {
if (frequencyMapB.get(availability) !== count) {
return false;
}
}

return true;
}

// Builds a frequency map of the Availability enums
private static buildFrequencyMap(
availabilities: Availability[],
): Map<Availability, number> {
const frequencyMap = new Map<Availability, number>();
for (const availability of availabilities) {
frequencyMap.set(availability, (frequencyMap.get(availability) || 0) + 1);
}
return frequencyMap;
}
}
2 changes: 1 addition & 1 deletion src/prerequisite/prerequisite.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class PrerequisiteController {
@Query('courseCode') courseCode: string,
): Promise<PrerequisiteCodeDto[]> {
return this.prerequisiteService.getPrerequisitesByCode(
courseCode,
courseCode.toUpperCase(),
programId,
);
}
Expand Down

0 comments on commit 0315767

Please sign in to comment.