Q:

Loop and Combine Time Ranges in an Array

I am trying to read through an array of objects (that are start/end times) and combine two (or more) of those times if they are back to back. 
ie. the first objects end time is the same as the next objects start time. If they are, combine them. Then check the newly combined objects end time with the next object in the array 
Here is a simplified array of times: 
var times = [
             {
              start: 1, 
              end: 2
             },{
              start: 2, 
              end: 3
             },{
              start: 4, 
              end: 5
             },{
              start: 6, 
              end: 7
             },
            ]

I would like that (or have a diff Array) to output like the below:
var newTimes = [
             {
              start: 1, 
              end: 3
             },{
              start: 4, 
              end: 5
             },{
              start: 6, 
              end: 7
             },
            ]

It gets trickier if there are 3 times in a row. 
var threeTime = [
             {
              start: 1, 
              end: 2
             },{
              start: 2, 
              end: 3
             },{
              start: 3, 
              end: 5
             },{
              start: 6, 
              end: 7
             },
            ]

The above should turn into:
var newThreeTimes = [
             {
              start: 1,  
              end: 5
             },{
              start: 6, 
              end: 7
             },
            ]

The original array of times will always be sorted from oldest (smallest start time) to newest (largest start time). The output does not need to be in any specific order. All time objects will be moment times.
Can someone help me solve this?

A:

This is the code i have come up with
function mergeArr(arr) {

    // Sort the array in descending order
    arr.sort(function(a, b) {
        return b.start - a.start;
    });

    // Traverse from the top as you will need to remove the elements
    // Merge the elements based on start of one and end of the previous
    for (var i = arr.length - 1; i > 0; i--) {
        if (arr[i].end == arr[i - 1].start) {
            arr[i].end = arr[i - 1].end;
            arr.splice(i - 1, 1);
        }
    }

    // Sort it again in reverse order.
    return arr.sort(function(a, b) {
        return a.start - b.start;
    });
}

Comments are making the code self explanatory.
Working Fiddle

