factorial of a number

前端 未结 28 2503
滥情空心
滥情空心 2020-12-09 11:57

I have the following code but it is not giving perfect result for factorial can u find it out plz



        
28条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 12:52

    What about:

    function fact(n) {
      n = Math.round(n);
      if (n < 2) {
        return 1;
      }
      else {
        return n * fact(n - 1);
      }
    }
    

    ?

提交回复
热议问题