Sorts an array using the Hybrid TimSort algorithm with adaptive run detection and memory optimization.
The type of elements in the array.
The array to be sorted.
Comparison function to determine sort order.
Optional
Configuration options, such as minGallop and minRunLength.
minGallop
minRunLength
The sorted array.
// Sorting an array of numbersconst arr = [3, 1, 4, 1, 5];const sortedArr = timSort(arr, (a, b) => a - b);console.log(sortedArr); // [1, 1, 3, 4, 5] Copy
// Sorting an array of numbersconst arr = [3, 1, 4, 1, 5];const sortedArr = timSort(arr, (a, b) => a - b);console.log(sortedArr); // [1, 1, 3, 4, 5]
// Sorting an array of stringsconst arr = ['banana', 'apple', 'cherry'];const sortedArr = timSort(arr, (a, b) => a.localeCompare(b));console.log(sortedArr); // ['apple', 'banana', 'cherry'] Copy
// Sorting an array of stringsconst arr = ['banana', 'apple', 'cherry'];const sortedArr = timSort(arr, (a, b) => a.localeCompare(b));console.log(sortedArr); // ['apple', 'banana', 'cherry']
Sorts an array using the Hybrid TimSort algorithm with adaptive run detection and memory optimization.