def binary_search_array(array, x, l=None, r=None, side="left"):
    """
    Binary search through a sorted array.
    """

    l = 0 if l is None else l
    r = len(array) - 1 if r is None else r
    mid = l + (r - l) // 2

    if l > r:
        return l if side == "left" else r

    if array[mid] == x:
        return mid
    elif x < array[mid]:
        return binary_search_array(array, x, l=l, r=mid - 1)
    else:
        return binary_search_array(array, x, l=mid + 1, r=r)