const arr = [21, 2, 5, 3, 1, 2, 6, 3, 3]; function quick(data) { if (data.length <= 1) { return data; } const base = data[0]; const left = [], right = []; for (var i = 1; i < data.length; i++) { if (data[i] < base) { left.push(data[i]); } else { right.push(data[i]); } } return quick(left).concat(base, quick(right)); } const res = quick(arr) console.log(res);