Three Ways to Factorialize a Number in JavaScript
Sonya Moisset

I used for loop & reduce to achieve the solution.

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

At first, I’d defined the array in the global space and for that reason editor was printing out the right result but it wasn’t taking the answer as correct. So, I moved var arr = []; within the function. And rightly so, because one should avoid using a global variable as much as possible.