1.求阶乘
1 2 3 4 5 6 7 |
function factorial(num){ if(num<=1){ return 1; }else{ return num*arguments.callee(num-1); } } |
2.求随机数n到m之间的数,包含m和n
1 2 3 |
function selectFrom(lowerValue,upperValue){ return Math.floor(Math.random()*(upperValue-lowerValue+1)+lowerValue); } |