@ts-standard-library/algorithms
Version:
A collection of algorithms for TypeScript.
14 lines (13 loc) • 744 B
TypeScript
/**
* Sorts an array using the selection sort algorithm.
*
* Iterates through the array, repeatedly finding the minimum element
* from the unsorted portion and swapping it with the first unsorted element.
*
* @typeParam T - The type of elements in the array.
* @param array - The array to be sorted. The sorting is done in-place.
* @param compareFn - A comparison function that returns a negative number if the first argument is less than the second, zero if they're equal, and a positive number otherwise.
* @returns The sorted array.
* @see {@link https://en.wikipedia.org/wiki/Selection_sort} for more information on selection sort.
*/
export declare function selectionSort<T>(array: T[], compareFn: (a: T, b: T) => number): T[];