Skip to content

Commit 3f64527

Browse files
committed
Fix accessing undefined bug
1 parent f877fff commit 3f64527

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • ctu-timetable-generator/src/app/generator

ctu-timetable-generator/src/app/generator/lib.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function mergeConflictingEventsInTimeTable(
5353
const newEventsThisDay: TimeTableEvent[] = [];
5454
const roomsSet = new Set<string>();
5555
for (const event of events) {
56-
const lastEventEnd = newEventsThisDay[newEventsThisDay.length - 1].end;
57-
if (newEventsThisDay.length === 0 || calcTimeDiff(lastEventEnd[0], lastEventEnd[1], event.start[0], event.start[1]) < 0) {
56+
const lastEventEnd = newEventsThisDay.length === 0 ? null : newEventsThisDay[newEventsThisDay.length - 1].end;
57+
if (lastEventEnd === null || calcTimeDiff(lastEventEnd[0], lastEventEnd[1], event.start[0], event.start[1]) < 0) {
5858
// No overlap with the last event
5959
newEventsThisDay.push(event);
6060
roomsSet.clear();

0 commit comments

Comments
 (0)