Factorialize a Number. Messy solution?

Hi, could someone look at my code please. I can pass the test but i think my solution may be a bit messy. Could someone let me know please?

Also, am i missing something?, why return a 1 from 0. 1 is not the factor for 0, I asked google. :slight_smile: this requirement is what is making the code look messy i think.

Cheers

Mark

 function factorialize(num) {
      var numbers = [];                 //empty array to fill
      var high = num;                   //sets (num) as "high" number
      var low = 0;                        //sets iteration stop
      
      
      //if else fills challenge requirement of returning 1 from 0 only
      if (num > 0)

      //creates an array by iterating (num)
      for (var i = high; i > low; i--){
      numbers.push(i);
          }
        
      //multiply array items to get factor
      factored = numbers.reduce(function(high, low) {
      return low * high;
      });
      return factored;
         
      }
      
      else { 
        return 1;
      }
    }


    factorialize(20);
1 Like