SOURCE

function qsort(arr, l, r) {
    if (l >= r) return arr;
	let i = l - 1;
	let j = r;
	let x = arr[l + r >> 1];
	while (i < j) {
		do ++i; while (arr[i] < x);
		do --j; while (arr[j] > x);
		if (i < j) {
			let temp = arr[i];
			arr[i] = arr[j];
			arr[j] = temp;
		}
	}
	return qsort(arr, l, j), qsort(arr, j + 1, r);
}

function sort(arr) {
	return   qsort(arr, 0, arr.length - 1);
}

const nums = [2, 4, 1, 6, 5, 3, 7];
// 输出 [1, 2, 3, 4, 5, 6, 7]
console.log(sort(nums));
console 命令行工具 X clear

                    
>
console