function merge(array, compareFunction, startIndex, middleIndex, endIndex) {
  var leftElements = new _linkedList.default();
  var rightElements = new _linkedList.default();
  var leftSize = middleIndex - startIndex;
  var rightSize = endIndex - middleIndex;
  var maxSize = Math.max(leftSize, rightSize);
  var size = endIndex - startIndex;

  for (var _i = 0; _i < maxSize; _i += 1) {
    if (_i < leftSize) {
      leftElements.push(array[startIndex + _i]);
    }

    if (_i < rightSize) {
      rightElements.push(array[middleIndex + _i]);
    }
  }

  var i = 0;

  while (i < size) {
    if (leftElements.first && rightElements.first) {
      if (compareFunction(leftElements.first.data, rightElements.first.data) > 0) {
        array[startIndex + i] = rightElements.shift().data;
      } else {
        array[startIndex + i] = leftElements.shift().data;
      }
    } else if (leftElements.first) {
      array[startIndex + i] = leftElements.shift().data;
    } else {
      array[startIndex + i] = rightElements.shift().data;
    }

    i += 1;
  }

  return array;
}
Devides and sort merges two subarrays of given array

@param {Array} array The array which subarrays should be sorted.
@param {Number} startIndex The start of the first subarray.
  This subarray is with end middle - 1.
@param {Number} middleIndex The start of the second array.
@param {Number} endIndex end - 1 is the end of the second array.
@returns {Array} The array with sorted subarray.