直接上代码咯~~~
有时间自己想了一下 其实很简单的
bubbleSort (arr) { let newArr = [] arr.map(e = > { if(newArr.length==0){ newArr[0] = e }else{ let array = [] let max = 0 newArr.map((ele,index) => { max = e > ele ? e : ele array[index] = e > ele ? ele : e }) array.push(max) newArr = array } }) return newArr } bubbleSort([3,54,6,5,7,2,65,9]) //[2,3,5,6,7,54,65]