From 0315767563f198dd2bf5b7d142b7bfc806451b66 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Fri, 29 Nov 2024 01:45:33 -0500 Subject: [PATCH] fix --- .../course-instance/courseInstanceUtil.ts | 19 +++++++++++++++---- src/prerequisite/prerequisite.controller.ts | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/utils/course-instance/courseInstanceUtil.ts b/src/common/utils/course-instance/courseInstanceUtil.ts index 24eb0ea..01d60e4 100644 --- a/src/common/utils/course-instance/courseInstanceUtil.ts +++ b/src/common/utils/course-instance/courseInstanceUtil.ts @@ -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 { + const frequencyMap = new Map(); + for (const availability of availabilities) { + frequencyMap.set(availability, (frequencyMap.get(availability) || 0) + 1); + } + return frequencyMap; + } } diff --git a/src/prerequisite/prerequisite.controller.ts b/src/prerequisite/prerequisite.controller.ts index aceee3e..877026e 100644 --- a/src/prerequisite/prerequisite.controller.ts +++ b/src/prerequisite/prerequisite.controller.ts @@ -49,7 +49,7 @@ export class PrerequisiteController { @Query('courseCode') courseCode: string, ): Promise { return this.prerequisiteService.getPrerequisitesByCode( - courseCode, + courseCode.toUpperCase(), programId, ); }