Hello this is one of my first post in the forum. As many of you I am learning code and I got to the yucky part of algorithms in javascript. I’m in the factorialize a Number challenge but I went to a path the uses arrays to find the factorial. I know there are better and simpler ways to solve this problem but for now I want to stick to the array way. First I wanted to create an array of elements then after getting this array elements I wanted to use the reduce method.
This is my code so far:
function factorialize(num) {
//Decrement from 5 to 0
var numArray = [];
for (i = num; i > 0; i–){
numArray.push(i);
}
//Get decrement Array
return numArray;
//Multiply array elements
var multiplyArrays = numArray.reduce(function(a, b) {
return a * b;
}, 0);
}
In the part multiplyArray I get an error saying “unreachable var after return”. What does it mean? What do I need to do make the reduce method work?
Thanks for all your help here.