UNPKG

@ts-standard-library/algorithms

Version:

A collection of algorithms for TypeScript.

16 lines (15 loc) 896 B
/** * Sorts an array using the highly inefficient bogo sort algorithm, which repeatedly shuffles the array * until it is sorted according to the provided comparison function. * * @param array - The array to be sorted. * @param compareFn - A function that defines the sort order. It should return a negative value if the first argument is less than the second, zero if they're equal, and a positive value otherwise. * @returns The sorted array. Note: The sorting is performed in-place and the original array is mutated. * * @remarks * Bogo sort is an intentionally inefficient sorting algorithm and should not be used for practical purposes. * Its average time complexity is O((n+1)!), making it impractical for all but the smallest arrays. * * Like for real, don't use this in production... */ export declare function bogoSort<T>(array: T[], compareFn: (a: T, b: T) => number): T[];