Help with Factorialize a Number algorithm

Help with Factorialize a Number algorithm
0.0 0

#1

help, i have been for two hours trying to figure out how to resolve this… used while, for… but i cant do the last part.

this is what i have:

thanks for the help.


#2

https://forum.freecodecamp.com/search?q=factorialize%20a%20number


#3

You are not allowed to call reduce on an empty array without an initial value. Passing a “initial value” of 1 solves the problem.

function factorialize(num){
  var array = [];
  for(var i = 1; i <= num; i++){
    array.push(i);
  }
  
  factor = array.reduce(function(a,b){
    return a*b;
  }, 1);
  
  return factor;
}