去重
案例
<script type="text/javascript">
var arr = [10,20,30,40,10];//10
var arr1 = [];
for(var i = 0; i < arr.length; i++){
if(arr[i] != 10){
arr1[i] = arr[i];
}
arr1[0] = 10;
}
console.log(arr1);
</script>
冒泡排序
<script type="text/javascript">
var arr = [100,90,111,250,8,5,3];
//1-循环 比较 两两比较
//每次循环执行一轮
for(var i = 0; i < arr.length;i++){
//每一轮里比较的次数
for(var j = 0;j <arr.length-1;j++){
if(arr[j] > arr[j+1]){
// arr[j] = 100
// arr[j+1] = 90
// tmp =arr[j] =100;
// arr[j] = arr[j+1] = 90
// arr[j+1] = tmp = 100
var tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
// document.write(arr[j]+"<br/>");
// document.write(arr[j+1]+"<br/>");
}
}
console.log(arr);
</script>