Trying to find factors of a number in JS

前端 未结 13 2860
陌清茗
陌清茗 2021-02-19 04:52

I am just starting JS, and understand the concept of finding a factor. However, this snippet of code is what I have so far. I have the str variable that outputs nothing but the

相关标签:
13条回答
  • 2021-02-19 05:43
    function factorialize(num) { 
     if(num === 0)
       return 1; 
     var arr = []; 
     for(var i=1; i<= num; i++){
       arr.push(i);
     } 
     num = arr.reduce(function(preVal, curVal){
       return preVal * curVal;
     });
    
      return num;
    }
    
    factorialize(5);
    
    0 讨论(0)
提交回复
热议问题