Skip to content

Typed API (TypeDoc)


Typed API (TypeDoc) / quicksort

Function: quicksort() ​

quicksort<V>(collection, comparator, factory): ICollection<V>

Defined in: sort/index.ts:35

Type Parameters ​

V ​

V

Value type.

Parameters ​

collection ​

ICollection<V>

Target collection (mutated while sorting).

comparator ​

Comparator<V>

Comparator used for ordering.

factory ​

() => ICollection<V>

Factory used to allocate temporary collections.

Returns ​

ICollection<V>

Sorted collection instance from the factory.

Description ​

Sort a collection by recursively partitioning around a pivot.

Example ​

ts
const sorted = quicksort(list, createComparator('score'), () => new List())

Remarks ​

Complexity: Average O(n log n), worst-case O(n²) when partitions are imbalanced.

Built with VitePress – Released under the MIT License.