冒泡排序
var re = [ 0,1,2,3,4];
for (let i = 0; i < re.length-1; i++) {
for (let j = 0; j < re.length-1; j++) {
if (re[j] < re[j+1]) {
re[j] = re.splice((j+1), 1, re[j])[0];
}
}
}
console.log(re);
//结果:[4, 3, 2, 1, 0]
var re = [ 0,1,2,3,4];
for (let i = 0; i < re.length-1; i++) {
for (let j = 0; j < re.length-1; j++) {
if (re[j] < re[j+1]) {
re[j] = re.splice((j+1), 1, re[j])[0];
}
}
}
console.log(re);
//结果:[4, 3, 2, 1, 0]