柯里化
function currying (fn, ...arg1) { if (arg1.length >= fn.length) { return fn(...arg1) } return function (...arg2) { return currying(fn, ...arg1, ...arg2) } }
求和
function add (...rest1) { const fn = function (...rest2) { rest1.push(...rest2) return fn } fn.toString = function () { return rest1.reduce((a, b) => a + b) } return fn }