Skip to content

Commit

Permalink
fix(timetable): add unique week check in formatNumericWeeks (#3677)
Browse files Browse the repository at this point in the history
Co-authored-by: Kok Rui Wong <kokruiwong@gmail.com>
  • Loading branch information
jloh02 and kokrui authored Mar 27, 2024
1 parent 711a6da commit be22c79
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions website/src/utils/timetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,12 @@ function parseModuleConfig(serialized: string | string[] | null): ModuleLessonCo
* - 1,2,3 => Weeks 1-3
* - 1,2,3,5,6,7 => Weeks 1-3, 5-7
*/
export function formatNumericWeeks(weeks: NumericWeeks): string | null {
export function formatNumericWeeks(unprocessedWeeks: NumericWeeks): string | null {
// Ensure list of weeks are unique
const weeks = unprocessedWeeks.filter(
(value, index) => unprocessedWeeks.indexOf(value) === index,
);

if (weeks.length === 13) return null;
if (weeks.length === 1) return `Week ${weeks[0]}`;

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

weeks.slice(1).forEach((next) => {
if (next - end === 1) {
if (next - end <= 1) {
// Consecutive week number - keep going
end = next;
} else {
Expand Down

0 comments on commit be22c79

Please sign in to comment.