Skip to content

Commit be22c79

Browse files
jloh02kokrui
andauthored
fix(timetable): add unique week check in formatNumericWeeks (#3677)
Co-authored-by: Kok Rui Wong <[email protected]>
1 parent 711a6da commit be22c79

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

website/src/utils/timetables.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,12 @@ function parseModuleConfig(serialized: string | string[] | null): ModuleLessonCo
484484
* - 1,2,3 => Weeks 1-3
485485
* - 1,2,3,5,6,7 => Weeks 1-3, 5-7
486486
*/
487-
export function formatNumericWeeks(weeks: NumericWeeks): string | null {
487+
export function formatNumericWeeks(unprocessedWeeks: NumericWeeks): string | null {
488+
// Ensure list of weeks are unique
489+
const weeks = unprocessedWeeks.filter(
490+
(value, index) => unprocessedWeeks.indexOf(value) === index,
491+
);
492+
488493
if (weeks.length === 13) return null;
489494
if (weeks.length === 1) return `Week ${weeks[0]}`;
490495

@@ -509,7 +514,7 @@ export function formatNumericWeeks(weeks: NumericWeeks): string | null {
509514
};
510515

511516
weeks.slice(1).forEach((next) => {
512-
if (next - end === 1) {
517+
if (next - end <= 1) {
513518
// Consecutive week number - keep going
514519
end = next;
515520
} else {

0 commit comments

Comments
 (0)