//方法4 functionbubbleSort4(arr) { let len = arr.length; let flag = true; for (let i = 0; i < len - 1 && flag; i++) { flag = false; for (let j = len - 1; j > i; j--) { if (arr[j] < arr[j - 1]) { let temp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = temp; flag = true; } } if (!flag) break; } return arr; }