how can i implement this logic add(1)(2)(1).. upto (n)?

Viewed 240

I know this question is already answered with limited capability but I want it with n number of time with n arguments?

function add(x) {
    return function(y) {
        if (typeof y !== 'undefined') {
            x = x + y;
            return arguments.callee;
        } else {
            return x;
        }
    };
}
add(1)(2)(3)(); //6
add(1)(1)(1)(1)(1)(1)(); //6

problem is this works only when I add extra empty brackets () it doesn't work if do this add(1)(2)(3)

reference question

3 Answers
Related