@mirei/ts-collections
    Preparing search index...

    Function binarySearch

    • Performs a binary search on the given sequence and returns the index of the element. The sequence must be sorted prior to calling this method. If the searched element exists multiple times in the sequence, the returned index is arbitrary.

      Type Parameters

      • TElement

        The type of the elements

      Parameters

      • sequence: Iterable<TElement>

        The iterable in which the element will be binary-searched for. It must be sorted.

      • element: TElement

        The element that will be searched for.

      • Optionalcomparator: OrderComparator<TElement, TElement>

        The comparator method that will be used to compare the elements. It should always be provided if the sequence is of a complex type.

      Returns number

      The index of the element that is equal to the searched element. If the element is not found, returns -1.