Function arrSortedInsertionIndex

  • Returns an index in the sorted array where the specified value could be inserted while maintaining the sorted order of the array. If the element is already in the array, returns the index after the last instance of the element.

    Type Parameters

    • T

    Parameters

    • array: readonly T[]

      The sorted array to search.

    • value: T

      The value to locate in the array.

    • comparator: ((a, b) => number)

      A function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.

        • (a, b): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns number

    The index at which the value could be inserted into array to maintain the array's sorted order.

    Example

    const array = [1, 2, 3, 5, 6];
    const value = 4;
    const comparator = (a, b) => a - b;
    const index = arrSortedLowerBound(array, value, comparator);
    console.log(index); // Output: 3

Generated using TypeDoc