code: function ChunkedStreamManager_groupChunks(chunks) {
        var groupedChunks = [];
        var beginChunk = -1;
        var prevChunk = -1;
        for (var i = 0; i < chunks.length; ++i) {
          var chunk = chunks[i];
  
          if (beginChunk < 0) {
            beginChunk = chunk;
          }
  
          if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
            groupedChunks.push({ beginChunk: beginChunk,
                                 endChunk: prevChunk + 1 });
            beginChunk = chunk;
          }
          if (i + 1 === chunks.length) {
            groupedChunks.push({ beginChunk: beginChunk,
                                 endChunk: chunk + 1 });
          }
  
          prevChunk = chunk;
        }
        return groupedChunks;
      }
docs: Groups a sorted array of chunks into as few continguous larger chunks as possible