标签:initial http back viewport init meta idt temp 版本
初级版本冒泡
<!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>
<script>
var arr=[5,4,3,2,1,3]
for( var j = 0; j<arr.length; j++){
for( var i = 0; i < arr.length; i++ ){
if( arr[i] > arr[i+1]){
var temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp
}
}
}
console.log(arr) // [1, 2, 3, 3, 4, 5]
</script>
</body>
</html>
中极版
<!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>
<script>
var arr=[5,4,3,2,1,3]
for( var j = 0; j<arr.length-1; j++){ // 遍数 : length-1
for( var i = 0; i < arr.length-1-j; i++ ){ // 每回 比较 length-1 次
if( arr[i] > arr[i+1]){
var temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp
}
}
}
console.log(arr) // [1, 2, 3, 3, 4, 5]
</script>
</body>
</html>
标签:initial http back viewport init meta idt temp 版本
原文地址:https://www.cnblogs.com/javascript9527/p/11433810.html