Q:

Javascript Code improvement - Integer factorial

I am learning to code with Javascript and one exercise is about returning the factorial of a provided integer. For example: 5! = 1 * 2 * 3 * 4 * 5 = 120
I came up with a result and it was accepted. However, I am not so sure it would be the most efficient way of solving this. 
Anyone would have any tips on how to improve this code?
function factorialize(num) {
    var array = [];  
    for (i = 1; i <= num; i++) {
        array.push(i);
    }
    var multi = 1;
    for (var i = 1; i < array.length; i++) {
        multi *= array[i];
    }
    return multi;
} 

Many thanks!!

A:

You have several approaches to get a solution.

by iteration
function f(n) {
    var r = n;
    while (--n) {
        r *= n;
    }
    return r;
}

by recursion
function f(n) {
    return n === 0 ? 1 : n * f(n - 1);
}

or a very short version
function f(n) {
    return +!~-n || n * f(n - 1);
}

