Function quickselect

  • Rearranges items so that all items in the [left, k] are the smallest. The k-th element will have the (k - left + 1)-th smallest value in [left, right].

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to partially sort (in place).

    • k: number

      The middle index for partial sorting.

    • Optional left: number

      The left index of the range to sort.

    • Optional right: number

      The right index.

    • Optional compare: ((a, b) => number)

      The compare function.

    Returns T[]