iter-fns - v0.13.0
    Preparing search index...

    Function quickselect

    • Finds the kth smallest element in an array using the quickselect algorithm.

      On average it runs in linear time and in the worst case it runs in quadratic time. In practice, due to a random pivot being used, the runtime will almost certainly be linear.

      The array is modified in place during the algorithm.

      If k is out of bounds (k < 0 or k >= length), returns undefined.

      Type Parameters

      • T

        type of the item

      Parameters

      • xs: T[]

        the array

      • k: number

        the index of the item if the array was sorted

      • cmp: Compare<T> = compare

        the comparator

      • rand: Random = random

        random number generator for pivot selection

      Returns undefined | T