我正在尝试为计划应用程序编写一个讲座碰撞算法。每个讲座都有一个开始和结束日期。
currentListElement是我当前日程中的现有讲座,我想添加selectedLecture,并检查我当前讲座之间是否存在冲突。因此,如果发生冲突,此布尔表达式应返回true。
感谢您的帮助
(currentListElement['startDate'] < chosenLecture['startDate']
|| currentListElement['startDate'] >= chosenLecture['endDate'])
&& (currentListElement['endDate'] <= chosenLecture['startDate']
|| currentListElement['endDate'] > chosenLecture['endDate'])
答案 0 :(得分:2)
实际上有一点错误,试试这个:
(currentListElement['endDate'] < chosenLecture['startDate']
|| currentListElement['startDate'] > chosenLecture['endDate'])
在两种情况下没有碰撞: