0

Below is the function. I just don't see how the "else" of that ternary operation could ever get executed, but if I'm missing something I'd like to know

wu.autoCurry = function (fn, numArgs) {
    numArgs = numArgs || fn.length;
    return function () {
        if (arguments.length < numArgs) {
            return numArgs - arguments.length > 0 ?
                wu.autoCurry(wu.curry.apply(this, [fn].concat(toArray(arguments))),
                             numArgs - arguments.length) :
                // in what situation would this line below run?
                wu.curry.apply(this, [fn].concat(toArray(arguments)));
        }
        else {
            return fn.apply(this, arguments);
        }
    };
};

Also here is their curry function:

wu.curry = function (fn /* variadic number of args */) {
    var args = ARR_SLICE.call(arguments, 1);
    return function () {
        return fn.apply(this, args.concat(toArray(arguments)));
    };
};
edhedges
  • 2,722
  • 2
  • 28
  • 61
  • Indeed, it will never run because `numArgs - arguments.length > 0` is equivalent to `numArgs > arguments.length` which is equivalent to `arguments.length < numArgs` which is the condition of the outer `if` statement. Anyway, I am voting to close this question as primarily opinion based because there's no way anyone (beside the person who wrote that code) is honestly going to know why he/she wrote it. – Aadit M Shah May 04 '15 at 14:47
  • @AaditMShah I've also voted to close it. I just asked because I thought it might be useful for others as well as wanting to know if I was missing something. – edhedges May 04 '15 at 19:10

0 Answers0