Why is my solution not working
I used the reduce method here and i feel it should work can anyone help me out with this. The problem
Return the factorial of the provided integer.
If the integer is represented with the letter n , a factorial is the product of all positive integers less than or equal to n .
Factorials are often represented with the shorthand notation n!
For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
Only integers greater than or equal to zero will be supplied to the function.
**This is the code I have written**
function factorialize(num) {
let ourArray = []
for (let i = 1; i <= num ; i++)
{
ourArray.push(i)
}
let product = 0
if(num === 0){
product = 1;
}else{
product = ourArray.reduce((num1,num2)=>{
return num1 * num2;
});
}
return product
}
console.log(factorialize(5));
Well, it looks like you’ve changed your reduce callback as well. product used to hold the product in your previous implementation, you should change that back.
I think you’re confused about how the callback works, but you have two functions, and therefore need two returns.