Trying to find factors of a number in JS

前端 未结 13 2793
陌清茗
陌清茗 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:37

    function factorialize(num) {
     var result = '';
      if( num === 0){
        return 1;
      }else{
        var myNum = [];
    
      for(i = 1; i <= num; i++){
        myNum.push(i);
        result = myNum.reduce(function(pre,cur){
          return pre * cur;
        });
      }
         return result;
        }
    }
    
    factorialize(9);
    

提交回复
热议问题