<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script>
var list = [100, 30, 50, 180, 190, 170, 28, 50];
for (var j = 0; j < list.length - 1; j++) {
for (var i = 0; i < list.length - 1-j; i++) {
var firstNum = list[i];
var secondNum = list[i + 1];
if (firstNum > secondNum) {
list[i] = secondNum;
list[i + 1] = firstNum;
}
}
}
alert(list);
</script>
</html>
第一小轮:把最大的数移到最上面
第二小轮:把第二大的数移到上面
依次类推 即可得到升序排列