@jiminp/tooltool
    Preparing search index...

    Function bisectLeft

    • Locates the insertion point for target in sorted_arr to maintain sorted order. If target is already present, the insertion point is to the left of any existing entries.

      Parameters

      • sorted_arr: (number | bigint)[]

        The sorted array to search. Must be sorted in ascending order.

      • target: number

        The value to locate.

      Returns number

      The index where target should be inserted.

      • The time complexity is O(log n).
      • If the array is not sorted, the result is undefined.
      • This corresponds to Python's bisect_left.
      const arr = [1, 2, 4, 4, 6;
      bisectLeft(arr, 4); // Returns 2
      bisectLeft(arr, 3); // Returns 2