直接上代码咯~~~
现在有时间自己想了一下然后出来了 其实很简单的 上学时候其实学过一个叫数据结构的课还是什么课来着 记不清了 哇 当时觉得好难啊
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]