const arr = [5, 3, 7, 1, 4, 2, 2, 1, 9]; function quickSort(list) { if (list.length <= 1) { return list; } const left = []; const right = []; const target = list.shift(); for (let i = 0; i < list.length; i++) { if (list[i] <= target) { left.push(list[i]); } else { right.push(list[i]); } } return quickSort(left).concat(target, quickSort(right)); } console.log(quickSort(arr));