console.log("锋叔子的选择排序");//选择排序function selectSort(myArray){ var k = 0; var tmp = 0; //每次循环找出最大的值 for(var i = 0; i < myArray.length - 1; i++) { k = i; //找出最大值 for(var j = i; j < myArray.length; j++) { if(myArray[j] < myArray[k]) { k = j; } } tmp = myArray[i]; myArray[i] = myArray[k]; myArray[k] = tmp; } return myArray;}//测试排序function testSort(){ var myArray=initArray(); var myArrayAfterSort=selectSort(myArray); for (var i = 0; i < myArrayAfterSort.length; i++) { console.log(myArrayAfterSort[i]); };}//初始化数组function initArray(){ var myArray=[9,3,8,7]; return myArray;}testSort();