var arr=[3,1,2,5,9,4];
var len=arr.length,d;
for (var i = 0; i <len; i++) {
for (var o = 0; o <len; o++) {
if (arr[i]>arr[o]) {
d = arr[o];
// console.log(arr[i],1);
arr[o] = arr[i];
// console.log(d+"----"+arr[o] +"-----"+ arr[i])
arr[i] = d;
//console.log(arr);
};
};
};
console.log(arr);
原文:http://www.cnblogs.com/MichaelXu1/p/6402368.html