我的功能有一个我似乎无法解决的问题。现在,它说无法读取联接槽中未定义的属性“ split”

我正在使用的功能是

function joinslots(freeTimings){
    joined=[];
    if(freeTimings.length==1){
        joined.push(freeTimings);
}
    if(freeTimings.length>1){
        for(i=0;i<=freeTimings.length;){
        //console.log(freeTimings[i]);
        time0=freeTimings[i].split("-");
        first0=time0[0];
        last0=time0[1];
        time1=freeTimings[i+1].split("-");
        first1=time1[0];
        last1=time1[1];
        if(last0==first1){
            newfirst=first0;
            newlast=last1;
            newtime = newfirst+"-"+newlast;
            joined.push(newtime);
            if(i+2<freeTimings.length){
            time2=freeTimings[i+2]
            first2=time2[0];
            last2=time2[1];
            if(first2==last1){
                 i=i+2;
            }
            else i++;
            }
            else i+=2;
        }
        else{
            joined.push(freeTimings[i]);
            i++;
        }  
        if(i==freeTimings.length-1){
            joined.push(freeTimings[i-1]);
            break;
        }      

    }

    }
    return joined;    



}

此功能的输入是30分钟的时间段,并且应尽可能返回一个小时的合并时间段。 每当我修复一个错误时,它都会引发另一个错误,这使我认为这里存在一个我无法弄清楚的潜在问题,除了数组超出范围之外,而我为此保留了一条if语句。

例如,输入为

freeTimings=["8:00-8:30","8:30-9:00","9:00-9:30","12:00-12:30","12:30-13:00","13:00-13:30","13:30-14:00","14-14:30","15:30-16:00","16:00-16:30","17:30-18:00"]

返回值必须是

joined=["8:00-9:00","9:00-9:30","12:00-13:00","13:00-14:00","14:00-14:30","15:30-16:30","17:30-18:00"]

因此,在修复我的功能方面的任何帮助将不胜感激:)