function sortMergeProgram(day) {
    var program = getProgram(day);
    program.sort(function(a, b){return parseTime(a[0])-parseTime(b[0])});
    for (var i = 0; i < program.length - 1; i++) {
        if (parseTime(program[i][1]) >= parseTime(program[i+1][0])) {
            var start = (program[i][0]);
            var end = (parseTime(program[i][1]) > parseTime(program[i+1][1])) ? program[i][1] : program[i+1][1];
            program.splice(i, 2);
            program.push([start, end]);
            sortMergeProgram(day);
            break;
        }
    }
}
/* Sorts the heating periods (the periods when the heating is on) and merges overlapping ones
*/
Sorts the heating periods (the periods when the heating is on) and merges overlapping ones
Sorts the heating periods ( the periods when the heating is on ) and merges overlapping ones
function sortMergeProgram(day) {
    var program = getProgram(day);
    program.sort(function(a, b){return parseTime(a[0])-parseTime(b[0])});
    for (var i = 0; i < program.length - 1; i++) {
        if (parseTime(program[i][1]) >= parseTime(program[i+1][0])) {
            var start = (program[i][0]);
            var end = (parseTime(program[i][1]) > parseTime(program[i+1][1])) ? program[i][1] : program[i+1][1];
            program.splice(i, 2);
            program.push([start, end]);
            sortMergeProgram(day);
            break;
        }
    }
}
function sortMergeProgram ( day ) { var program = getProgram ( day ) ; program . sort ( function ( a , b ) { return parseTime ( a [ 0 ] ) - parseTime ( b [ 0 ] ) } ) ; for ( var i = 0 ; i < program . length - 1 ; i ++ ) { if ( parseTime ( program [ i ] [ 1 ] ) >= parseTime ( program [ i + 1 ] [ 0 ] ) ) { var start = ( program [ i ] [ 0 ] ) ; var end = ( parseTime ( program [ i ] [ 1 ] ) > parseTime ( program [ i + 1 ] [ 1 ] ) ) ? program [ i ] [ 1 ] : program [ i + 1 ] [ 1 ] ; program . splice ( i , 2 ) ; program . push ( [ start , end ] ) ; sortMergeProgram ( day ) ; break ; } } }
Sorts the heating periods (the periods when the heating is on) and merges overlapping ones
Sorts the heating periods ( the periods when the heating is on ) and merges overlapping ones