关于选择排序,将一组数,从小到大选择排序
var arr = [5, 4, 3, 2, 1];
for (var j = 0; j < arr.length - 1; j++) {
for (var i = j + 1; i < arr.length; i++) {
if (arr[i] < arr[j]){
var tmp;
tmp = arr[i];
arr[i] = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
console.log(arr);