// 冒泡排序 const bubbleSort = (arr = []) => { const list = arr.slice() const len = list.length for (let i = 0; i < len; i++) { let exchange = false for (let j = len - 1; j > i; j--) { if (list[j] < list[j - 1]) { [list[j - 1], list[j]] = [list[j], list[j - 1]] exchange = true } } if (!exchange) return list } return list } const array = [4, 6, 8, 5, 9, 1, 2, 5, 3, 2] console.log(bubbleSort(array))