![const quickSort = (array, equalPredicate, lessThanPredicate) => { const arrayCopy = [...array]; if (arrayCopy.length <= 1) { return arrayCopy; } const pivotElement = arrayCopy.shift(); const left = []; const right = []; const center = [pivotElement]; while (arrayCopy.length) { const currentElement = arrayCopy.shift(); if (equalPredicate(currentElement, pivotElement)) { center.push(currentElement); } else if (lessThanPredicate(currentElement, pivotElement)) { left.push(currentElement); } else { right.push(currentElement); } } const leftSorted = quickSort(left, equalPredicate, lessThanPredicate); const rightSorted = quickSort(right, equalPredicate, lessThanPredicate); return leftSorted.concat(center, rightSorted); };](https://pbs.twimg.com/media/E-07P91X0AALlKo.jpg?name=small&format=webp)
ALT const quickSort = (array, equalPredicate, lessThanPredicate) => { const arrayCopy = [...array]; if (arrayCopy.length <= 1) { return arrayCopy; } const pivotElement = arrayCopy.shift(); const left = []; const right = []; const center = [pivotElement]; while (arrayCopy.length) { const currentElement = arrayCopy.shift(); if (equalPredicate(currentElement, pivotElement)) { center.push(currentElement); } else if (lessThanPredicate(currentElement, pivotElement)) { left.push(currentElement); } else { right.push(currentElement); } } const leftSorted = quickSort(left, equalPredicate, lessThanPredicate); const rightSorted = quickSort(right, equalPredicate, lessThanPredicate); return leftSorted.concat(center, rightSorted); };


















