1. <script><br /> //函数封装冒泡排序 sort排序<br /> functionsort (arr) {<br /> for(varj = 1; j < arr.length - 1; j++){<br /> for(vari = 0; i <= arr.length - j - 1; i++){<br /> if(arr[i] > arr[i + 1]){<br /> vartemp;<br /> temp = arr[i + 1];<br /> arr[i + 1] = arr[i];<br /> arr[i] = temp;<br /> }<br /> }<br /> }<br /> returnarr;<br /> }<br /> vararr1 = sort([3,8,2,6,4,9,7,1,5]);<br /> console.log(arr1);<br /> </script>

    .