function partial(fn) {
var args = Array.prototype.slice.call(arguments);
var args = args.slice(1);
return function() {
var args1 = Array.prototype.slice.call(arguments);
var newArgs = args.concat(args1);
var j = 0;
for (var i = 0; i < newArgs.length; i++) {
if (newArgs[i] === undefined) {
newArgs[i] = arguments[j];
j++;
};
};
var x = fn.apply(null, newArgs);
return x;
}
}
function test(a, b, c, d) { return 'a=' + a + ',b=' + b + ',c=' + c + ',d=' + d; }
var test1_3 = partial(test, 1, undefined, undefined, 3);
console.log(test1_3(5, 6));
console.log(test1_3(4, 1));
ZnVuY3Rpb24gcGFydGlhbChmbikgewkKCXZhciBhcmdzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzKTsKCXZhciBhcmdzID0gYXJncy5zbGljZSgxKTsKCglyZXR1cm4gZnVuY3Rpb24oKSB7CgkJdmFyIGFyZ3MxID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzKTsKIAkJdmFyIG5ld0FyZ3MgPSBhcmdzLmNvbmNhdChhcmdzMSk7CiAJCXZhciBqID0gMDsKIAkJZm9yICh2YXIgaSA9IDA7IGkgPCBuZXdBcmdzLmxlbmd0aDsgaSsrKSB7CiAJCQlpZiAobmV3QXJnc1tpXSA9PT0gdW5kZWZpbmVkKSB7CiAJCQkJbmV3QXJnc1tpXSA9IGFyZ3VtZW50c1tqXTsKIAkJCQlqKys7CiAJCQl9OwogCQl9OwogCQl2YXIgeCA9IGZuLmFwcGx5KG51bGwsIG5ld0FyZ3MpOwoJCXJldHVybiB4OwoJfQp9CgoKZnVuY3Rpb24gdGVzdChhLCBiLCBjLCBkKSB7IHJldHVybiAnYT0nICsgYSArICcsYj0nICsgYiArICcsYz0nICsgYyArICcsZD0nICsgZDsgfQp2YXIgdGVzdDFfMyA9IHBhcnRpYWwodGVzdCwgMSwgdW5kZWZpbmVkLCB1bmRlZmluZWQsIDMpOwpjb25zb2xlLmxvZyh0ZXN0MV8zKDUsIDYpKTsgCmNvbnNvbGUubG9nKHRlc3QxXzMoNCwgMSkpOyA=