// Write custom polyfill for Sort ?
const sortArray = function (nums) {
function quickSort(l, h) {
if (l >= h) return; // Base case: invalid range
const index = partition(l, h); // Partition the array
quickSort(l, index - 1); // Recursively sort left part
quickSort(index, h); // Recursively sort right part
function partition(l, h) {
const pivot = nums[Math.floor((l + h) / 2)]; // Choose pivot element
while (nums[l] < pivot) l++; // move left pointer
while (nums[h] > pivot) h--; // Move right pointer
[nums[l], nums[h]] = [nums[h], nums[l]]; // Swap elements
quickSort(0, nums.length - 1); // Start QuickSort
return nums; // Return the sorted array
const arr = [21, 31, 45, 56, 43];
console.log(sortArray(arr));
//you can also go for merge sort