利用函数封装冒泡顺序
sort 函数实现过程
function sort(arr) {
for (var i = 0; i < arr.length - 1; i++) {
for (var j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
var temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
var arr2 = sort([5, 7, 11, 9, 6]);
console.log(arr2);
标签:sort,arr,顺序,封装,函数,冒泡,var From: https://www.cnblogs.com/Juny-J/p/17054385.html