merge-sort-nat
Version:
Merge sort library made for testing class
15 lines (14 loc) • 626 B
TypeScript
import { Compare } from "../types";
/**
* Sorts array with merge sort algorithm
* @param array Array to sort
* @param compareFunction Compares two values of array. If output of function is below 0, it takes firstElement, else if output is above 0, it takes secondElement, else if output is equal 0, it does not change order of elements
* @returns New sorted array
* @example
* Example of sorting array:
* ```js
* let sortedArray = mergeSort([5, 4, 3, 2, 1] (a, b) => a - b); // Sort array in ascending order
* ```
*/
declare function mergeSort<T>(array: T[], compareFunction: Compare<T>): T[];
export { mergeSort };