JSFiddle - React, Tailwind, and code Playground
JavaScript
function partial2(func) {
var self = func, boundArgs = arguments;
return function() {
var args = Array.prototype.slice.call(boundArgs, 1);
var insideArgs = Array.prototype.slice.call(arguments, 0);
var finalArgs = args.concat(insideArgs);
return self.apply(this, finalArgs);
}
}
var add5_2 = partial2(add, 5);
console.log(add5_2(2)); // 7
console.log(add5_2(10)); // 15
console.log(add5_2(8)); // 13
var mult23_2 = partial2(mult, 2, 3);
console.log(mult23_2(4, 5)); // 2*3*4*5 = 120
console.log(mult23_2(1, 1)); // 2*3*1*1 = 6