比较js / jquery中的所有数组元素

时间:2012-08-23 10:17:36

标签: javascript jquery ajax jquery-ui

以下是当前代码的演示:http://mobilocloud.com/schedule/

我有一个包含多个数组的js对象,每个数组有两个时间哈希值(一个开始时间和一个结束时间/我使用getTime()得到它们)。我想比较对象中包含的所有数组,以检查时间范围之间的所有交叉点。我有脚本工作,但它一次只比较两个数组(最后我得到两个重叠事件的组)。我希望得到所有重叠事件的组,而不仅仅是两个。

以下是实际代码:

function _DetectOverlapedEvents(column) {
    events;
    groups;
    sgroups;
    todeoverlap[column] = new Array();
    groups[column] = new Array();
    sgroups[column] = new Array();
    var $curid=0;
    var $curevent= new Array();
    if(events[column].length > 1){
        $(events[column]).each(function(key, $secondevent) {
            //alert("Comparing : " + $curevent["name"] + " and " + $secondevent["name"] + "\n" + $curevent["starthash"] + "<" +$secondevent["endhash"] + " = " + ($curevent["starthash"] < $secondevent["endhash"]) + "\n&&\n" + $curevent["endhash"] + ">" + $secondevent["starthash"] + " = " + ($curevent["endhash"] > $secondevent["starthash"]));
            if($curevent.length<2) {
                $curevent=$secondevent;
            } else if(($curevent["starthash"] < $secondevent["endhash"]) && ($curevent["endhash"] > $secondevent["starthash"])) {
                //alert("added " + $curevent["name"] + " and " + $secondevent["name"]);
                toextend = {left: $curevent, right: $secondevent};
                groups[column].push(toextend);
                sgroups[column].push($curevent, $secondevent);
                //console.log("groups: " + JSON.stringify(groups[column]));
                $curid++;
            }
            $curevent = $secondevent;
        });
    }
    //console.log(JSON.stringify(groups));
}

0 个答案:

没有答案