javascript-collections-framework
    Preparing search index...

    Function sortedIndex

    • Returns the index at which key would be inserted into list, sorted ascending by comparator (natural order when omitted), to keep it sorted: the least index whose element does not compare less than key, or list.size when every element does. The result on an unsorted list is unspecified.

      Time: at most ⌈log₂(n + 1)⌉ comparator calls and as many get calls.

      Type Parameters

      • E

      Parameters

      • list: ReadonlyList<E>

        A list sorted by comparator.

      • key: E

        The value to place.

      • Optionalcomparator: Comparator<E>

        The order the list is sorted by; natural order when omitted.

      Returns number

      The insertion point, from 0 to list.size.

      TypeError when list is not a list from this library, comparator is not a function, or it returns a non-number or NaN.

      NullElementError when natural order meets null or undefined.

      ClassCastError when natural order meets values of different kinds.

      ConcurrentModificationError when the comparator changes the list.

      sortedIndex(new ArrayList([10, 20, 30]), 25) // 2