冒泡排序
let array = [2, 5, 3, 1, 4]
function sort(arr) {
let res = []
if(!Array.isArray(arr)) return []
for (var i = 0; i < arr.length; i++) {
for (var j = i + 1; j < arr.length; j++) {
if(arr[i] > arr[j]) {
let template = arr[i]
arr[i] = arr[j]
arr[j] = template
}
}
}
return res
}
console.log(sort(array), array)
标签:sort,arr,return,++,算法,let,array,排序
From: https://www.cnblogs.com/caijinghong/p/17309495.html