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>

运行结果

 

posted @ 2020-12-17 09:59  张先生zy  阅读(177)  评论(0编辑  收藏  举报