var s = [9,1,10,2,15,36974,3]
var temp;
var i;
var j;
// 从大到小排列
for(i = 0; i< s.length; i++){
for(j = 0; j< s.length-i; j++){
if(s[j] < s[j+1]){
temp = s[j+1]
s[j+1] = s[j]
s[j] = temp
}
}
}
从小到大排列
var s = [9,1,10,2,15,36974,3]
var temp;
var i;
var j;
for(i = 0; i< s.length; i++){
for(j = 0; j< s.length-i; j++){
if(s[j] > s[j+1]){
temp = s[j+1]
s[j+1] = s[j]
s[j] = temp
}
}
}
function fact(num) {
if (num <= 1) {
return 1;
} else {
return num * fact(num - 1);
}
}
fact(4)