📅  最后修改于: 2022-03-11 15:03:13.256000             🧑  作者: Mango
const bubbleSort = (arr) => {
let temp = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 1; j < arr.length; j++) {
if (arr[j - 1] > arr[i]) {
temp = arr[j - 1];
arr[j - 1] = arr[i];
arr[i] = temp;
}
}
}
return arr;
};
console.log(bubbleSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]));