Skip to content

Latest commit

 

History

History
29 lines (27 loc) · 615 Bytes

816.md

File metadata and controls

29 lines (27 loc) · 615 Bytes

Currying

var curry = function (fn) {
    var args = [].slice.call(arguments, 1);
    return function() {
        var newArgs = args.concat([].slice.call(arguments));
        return fn.apply(this, newArgs);
    };
};
function curry(fn, args) {
  var length = fn.length;
  args = args || [];
  return function() {
    var totalArgs = args.slice(), arg, i;
    for (i = 0; i < arguments.length; i++) {
      arg = arguments[i];
      totalArgs.push(arg);
    }
    if (totalArgss.length < length) {
      return curry.call(this, fn, totalArgss);
    }
    return fn.apply(this, totalArgss);
  }
}