Factorialize a Number - last condition?

Factorialize a Number - last condition?
0

#1

Tell us what’s happening:

This code, as far as I can tell, factorializes any number given it, took a lot of re-reading and such. But proud of myself.
However the final challenge test is factorialize(0) returns 1, which my code doesn’t pass.
Why is that a condition? Is 0! actually 1 in math? I can’t figure out how to make that happen. Any help appreciated.

Your code so far

function factorialize(num) {

  var array = [];
  for (num; num >= 1; num--) {
    array.push(num);
  }
  var product = array.reduce(function(previousVal, currentVal) {
   return previousVal * currentVal;});
  
  num = product;
  return num;
}

factorialize(0);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36.

Link to the challenge:


#2

Yes! 0! equals 1. You can add a special case in your code to check if the input is 0.


#3

Right on. What a crazy thing for 0 to do!