【问题标题】:Lecture collision boolean expression algorithm讲座碰撞布尔表达式算法
【发布时间】:2014-01-25 19:02:30
【问题描述】:

我正在尝试为日程应用程序编写讲座冲突算法。每个讲座都有开始和结束日期。

currentListElement 是我当前日程中的现有讲座,我想添加 selectedLecture,并检查我当前的讲座之间是否存在冲突。因此,如果发生碰撞,这个布尔表达式应该返回 true。

感谢您的帮助

(currentListElement['startDate'] < chosenLecture['startDate'] 
  || currentListElement['startDate'] >= chosenLecture['endDate']) 
 && (currentListElement['endDate'] <= chosenLecture['startDate'] 
  || currentListElement['endDate'] > chosenLecture['endDate'])

【问题讨论】:

    标签: boolean-logic boolean-expression boolean-operations


    【解决方案1】:

    其实有个小错误,试试这个:

    (currentListElement['endDate'] < chosenLecture['startDate'] 
     || currentListElement['startDate'] > chosenLecture['endDate'])
    

    两种情况都没有碰撞:

    1. 讲座完全设置在当前讲座之前。要检查这一点,只需确保它在当前开始之前结束。
    2. 讲座完全设置在当前讲座之后。要检查这一点,只需确保它在电流结束后开始。

    【讨论】:

      猜你喜欢
      • 2012-11-24
      • 2011-07-15
      • 2016-06-30
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多