# 冒泡排序 ```JavaScript let a = [6,8,9,5,1,3,5,4,6,7] function bubbleSort(arr) { for (let i=0; arr.length>i; i++) { for (let n=0; arr.length>n; n++) { // 如果前者小于后者, 则交换位置 if (arr[i] < arr[n]) { let tmp = arr[n] arr[n] = arr[i] arr[i] = tmp } } } return arr } bubbleSort(a) // [ 1, 3, 4, 5, 5, 6, 6, 7, 8, 9] ```