function quickSort(arr) {
if (arr.length <= 1) {
return arr
}
const mid = arr.length >> 1
const pivot = arr[mid]
const left = []
const right = []
for (const num of arr) {
if (num < pivot) {
left.push(num)
} else if (num > pivot) {
right.push(num)
}
}
return [...quickSort(left), pivot, ...quickSort(right)];
}
const array = [8, 3, 2, 5, 9, 1, 6, 4, 7,22];
const sortedArray = quickSort(array);
console.log(sortedArray);