function binaryFindIndex(array, index) {
    let lowerIndex = 0;
    let middleIndex = 0;
    let upperIndex = index - 1;
    let nextValue = array[index]
    let nextValueIndex;
    let indexFound = false
    index >= array.length ? (nextValueIndex = -1, indexFound = true) : null;
    while (upperIndex >= lowerIndex && !indexFound) {
        middleIndex = Math.floor((upperIndex + lowerIndex) / 2);
        if (upperIndex === lowerIndex || nextValue === array[middleIndex]) {
            nextValue > array[middleIndex] ? (nextValueIndex = middleIndex + 1, indexFound = true) : (nextValueIndex = middleIndex, indexFound = true)
        } else if (nextValue < array[middleIndex]) {
            upperIndex = middleIndex - 1;
        } else if (nextValue > array[middleIndex]) {
            lowerIndex = middleIndex + 1;
        }
    }

    return indexFound ? nextValueIndex : lowerIndex;
}
//binaryFindIndex is a function that performe a binary search and return an index where a given value(index of a value) should be inserted. 
binaryFindIndex is a function that performe a binary search and return an index where a given value(index of a value) should be inserted.
binaryFindIndex is a function that performe a binary search and return an index where a given value ( index of a value ) should be inserted .
function binaryFindIndex(array, index) {
    let lowerIndex = 0;
    let middleIndex = 0;
    let upperIndex = index - 1;
    let nextValue = array[index]
    let nextValueIndex;
    let indexFound = false
    index >= array.length ? (nextValueIndex = -1, indexFound = true) : null;
    while (upperIndex >= lowerIndex && !indexFound) {
        middleIndex = Math.floor((upperIndex + lowerIndex) / 2);
        if (upperIndex === lowerIndex || nextValue === array[middleIndex]) {
            nextValue > array[middleIndex] ? (nextValueIndex = middleIndex + 1, indexFound = true) : (nextValueIndex = middleIndex, indexFound = true)
        } else if (nextValue < array[middleIndex]) {
            upperIndex = middleIndex - 1;
        } else if (nextValue > array[middleIndex]) {
            lowerIndex = middleIndex + 1;
        }
    }
    return indexFound ? nextValueIndex : lowerIndex;
}
function binaryFindIndex ( array , index ) { let lowerIndex = 0 ; let middleIndex = 0 ; let upperIndex = index - 1 ; let nextValue = array [ index ] let nextValueIndex ; let indexFound = false index >= array . length ? ( nextValueIndex = - 1 , indexFound = true ) : null ; while ( upperIndex >= lowerIndex && ! indexFound ) { middleIndex = Math . floor ( ( upperIndex + lowerIndex ) / 2 ) ; if ( upperIndex === lowerIndex || nextValue === array [ middleIndex ] ) { nextValue > array [ middleIndex ] ? ( nextValueIndex = middleIndex + 1 , indexFound = true ) : ( nextValueIndex = middleIndex , indexFound = true ) } else if ( nextValue < array [ middleIndex ] ) { upperIndex = middleIndex - 1 ; } else if ( nextValue > array [ middleIndex ] ) { lowerIndex = middleIndex + 1 ; } } return indexFound ? nextValueIndex : lowerIndex ; }
binaryFindIndex is a function that performe a binary search and return an index where a given value(index of a value) should be inserted.
binaryFindIndex is a function that performe a binary search and return an index where a given value ( index of a value ) should be inserted .