@ts-standard-library/algorithms
Version:
A collection of algorithms for TypeScript.
13 lines (12 loc) • 667 B
TypeScript
/**
* Sorts an array using the merge sort algorithm.
*
* @template T - The type of elements in the array.
* @param array - The array to be sorted.
* @param compareFn - A comparison function that defines the sort order.
* It should return a negative number if `a < b`, zero if `a === b`, and a positive number if `a > b`.
* @returns A new sorted array containing the elements of the input array.
* @see [Merge Sort Visualization](https://www.geeksforgeeks.org/merge-sort/)
* @see {@link https://en.wikipedia.org/wiki/Merge_sort} for more information on merge sort.
*/
export declare function mergeSort<T>(array: T[], compareFn: (a: T, b: T) => number): T[];