SOURCE

function sort(arr) {
	if (arr.length <= 1) {
		return arr;
	}
	let num, ind;
	let left = [], right = [];
	ind = Math.floor(arr.length / 2);
	num = arr.splice(ind, 1)[0];
	for (let i = 0; i < arr.length; i++) {
		if (arr[i] < num) {
			left.push(arr[i]);
		} else {
			right.push(arr[i]);
		}
	}
	return sort(left).concat(num, sort(right));
}
const nums = [2, 4, 1, 6, 5, 3, 7];
console.log(sort(nums));
console 命令行工具 X clear

                    
>
console