将数组[5,9,45,87,36,21,85,11,6,50]中的内容按照从小到大的顺序排列
let numArr=[5,9,45,87,36,21,85,11,6,50]
for (let j = 0; j < numArr.length - 1; j++){
for (let i = 0; i < numArr.length - 1 - j; i++){
if (numArr[i] > numArr[i + 1]){
let temp = numArr[i];
numArr[i] = numArr[i + 1];
numArr[i + 1] = temp;
}
}
}
将数组[5,9,45,87,36,21,85,11,6,50]中的内容按照从大到小的顺序排列
let numArr=[5,9,45,87,36,21,85,11,6,50]
for (let i = 0; i < numArr.length - 1; i++){
for (let j = 0; j < numArr.length - 1 - i; j++){
if (numArr[j+1] > numArr[j]){
let temp = numArr[j];
numArr[j] = numArr[j + 1];
numArr[j + 1] = temp;
}
}
}