🔀 Array.prototype.sort() Polyfill
Category: js / polyfills
Difficulty: hard
The sort() method sorts the elements of an array in place and returns the sorted array. Here are two implementations: Bubble Sort and QuickSort. ✅ Bubble Sort Implementation [code example] Key Points about Bubble Sort : Time Complexity : O(n^2) (because of the nested loops). Space Complexity : O(1) (no extra space needed). Bubble Sort is a simple but inefficient sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order. QuickSort Implementation : ```javascript Array.prototype.customSort = function(compareFn) { if (typeof compareFn !== "function") { // Default sorting: Convert elements to strings and sort lexicographically compareFn = (a, b) => String(a) > String(b) ? 1 : (String(a) < String(b) ? -1 : 0); } // QuickSort Implementation const quickSort = (arr, left, right) => { if (left >= right) return; // Base case: stop when partition size is 1 or 0...