src/privates/_getInsertionIndex.js
function _getInsertionIndex (array, element, comparer, start, end) {
    if (array.length === 0) {
        return 0;
    }

    var pivot = (start + end) >> 1;
    var result = comparer(
        { value: element, index: pivot },
        { value: array[pivot], index: pivot }
    );

    if (end - start <= 1) {
        return result < 0 ? pivot : pivot + 1;
    } else if (result < 0) {
        return _getInsertionIndex(array, element, comparer, start, pivot);
    } else if (result === 0) {
        return pivot + 1;
    } else {
        return _getInsertionIndex(array, element, comparer, pivot, end);
    }
}
function _getInsertionIndex (array, element, comparer, start, end) {
    if (array.length === 0) {
        return 0;
    }

    var pivot = (start + end) >> 1;
    var result = comparer(
        { value: element, index: pivot },
        { value: array[pivot], index: pivot }
    );

    if (end - start <= 1) {
        return result < 0 ? pivot : pivot + 1;
    } else if (result < 0) {
        return _getInsertionIndex(array, element, comparer, start, pivot);
    } else if (result === 0) {
        return pivot + 1;
    } else {
        return _getInsertionIndex(array, element, comparer, pivot, end);
    }
}
function _getInsertionIndex ( array , element , comparer , start , end ) { if ( array . length === 0 ) { return 0 ; } var pivot = ( start + end ) >> 1 ; var result = comparer ( { value : element , index : pivot } , { value : array [ pivot ] , index : pivot } ) ; if ( end - start <= 1 ) { return result < 0 ? pivot : pivot + 1 ; } else if ( result < 0 ) { return _getInsertionIndex ( array , element , comparer , start , pivot ) ; } else if ( result === 0 ) { return pivot + 1 ; } else { return _getInsertionIndex ( array , element , comparer , pivot , end ) ; } }
Establishes at which index an element should be inserted in a sorted array to respect
the array order. Needs the comparer used to sort the array.
@private
@param {Array} array
@param {*} element
@param {Function} comparer
@param {Number} start
@param {Number} end
@returns {Number}
Establishes at which index an element should be inserted in a sorted array to respect the array order . Needs the comparer used to sort the array .