factorial of a number

前端 未结 28 2505
滥情空心
滥情空心 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条回答
  •  长情又很酷
    2020-12-09 12:54

    function factorial (n) {
      if (n > 1) {
        return n * factorial(n-1);
      }
      return 1;
    }
    console.log("recursive way => ",factorial(5)); 
    

提交回复
热议问题