< HTML > <head> <title> </title> </head> <body> <script> function sortarr(arr) {for (I = 0; i < arr.length - 1; i++) { for (j = 0; j < arr.length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { var temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } return arr; } function selectSort(arr) { var len = arr.length; var minIndex, temp; for (i = 0; i < len - 1; i++) { minIndex = i; for (j = i + 1; j < len; j++) { if (arr[j] < arr[minIndex]) { minIndex = j; } } temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; } console.timeEnd(' select sort time '); return arr; } / / * * * * * * * * * * * let arr =,3,2,8,5,7,4,6 [1] the console. The log (arr, "arr) / / bubble sort function mySort1 (arr) {for (let I = 0; i<arr.length; i++){ for(let j=i; j<arr.length; j++){ if(arr[i]>arr[j]){ let temp; temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } return arr } function selectSort(arr) { var len = arr.length; var minIndex, temp; for (i = 0; i < len - 1; i++) { minIndex = i; for (j = i + 1; j < len; j++) { if (arr[j] < arr[minIndex]) { minIndex = j; } } temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; } console.timeEnd(' select sort time '); return arr; } function selectSort1(arr){for(let I =0; i<arr.length-1; i++){ let minIndex = i; for(let j=i+1; j<arr.length; j++){ if(arr[j]<arr[minIndex]){ minIndex=j } } let temp=arr[i]; arr[i]= arr[minIndex]; arr[minIndex]=temp; } return arr; } console.log(selectSort1(arr),arr,"pppppppp") </script> </body> </html>Copy the code