A function corrification is a form of a higher-order function:
It allows a function a to pass in a set of arguments, and then that function returns another function B, which can process the arguments passed in when a is called. You can then continue calling function B and pass in the remaining arguments.
Here is an example of a function kerritization interview:
// Implement an add method that meets the following expectations: add(1)(2)(3) = 6; add(1, 2, 3)(4) = 10; add(1)(2)(3)(4)(5) = 15;
It’s worth noting that the toString method is called when an object is printed in console.log, so it’s overridden here.
function add() {let args=Array.prototype.slice.call(arguments);
function adder_(){
args=args.concat(Array.prototype.slice.call(arguments));
return adder_;
}
adder_.toString=()=>{
return args.reduce((a,b)=>{
returna+b; })}returnadder_; } the console. The log (add (1 and 4) (40) (50))Copy the code