Do you guys this is an okay code? Any suggestions for improvement?
function factorialize(num) {
var result = 1;
for (var i=num; i >= 1; i--) {
result *= i;
}
return result;
}
Do you guys this is an okay code? Any suggestions for improvement?
function factorialize(num) {
var result = 1;
for (var i=num; i >= 1; i--) {
result *= i;
}
return result;
}
Thanks a lot! Your feedback means a lot to me.
I used recursion to solve mine, just because I wanted to use it! Point noted. Great post as usual, @P1xt.
@Milos2709 Nice job! Your solution looks clean and efficient.
Thanks @dpberry552. I am glad these algorithm challenges arenβt as difficult as I feared them to be
Easy to understand
function factorialize(num) {
var result = 1; // set to 1 because multiplying to 0 results in 0
for(i=1; i<=num; i++){ // get 1,2,3,4,5
console.log(result *= i); // multiply 1*2*3*4*5*(1) = 120
}
}
factorialize(4);