js:阶乘算法
<script type="text/javascript"> function factorialize(num){ if(num<0){ return -1 }else if(num == 0 || num ==1){ return 1 }else{ return num * factorialize(num-1) } } var result = factorialize(5) console.log("result",result) </script>
运行结果
<script type="text/javascript"> function factorialize(num){ if(num<0){ return -1 }else if(num == 0 || num ==1){ return 1 }else{ return num * factorialize(num-1) } } var result = factorialize(5) console.log("result",result) </script>
运行结果