function newsort(arr, left, right){
for(var i= left; i < right; ++i){
var min = i;
for (var j = i; j < right; ++j){
if (arr[min] > arr[j]){
min = j;
}
}
var temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
return arr;
}
var arr = [3,5,66,78,23,44,11,32,58];
alert(newsort(arr, arr.length, 0));
Above is the code for a function that I have written. I am still very new to JS, and as a result get confused at times when it comes to syntax. I currently just return the original array, but am trying to do the selection sort, the right/left/mid type.....I can't really tell what is going on at the moment. I am simply trying to sort and then return the array.
Anyone out there able to point me in the right direction?
thanks.....
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…