\u6309\u4e00\u5b9a\u987a\u5e8f\u6267\u884c\u4e00\u7ec4\u65b9\u6cd5\uff0c\u5bf9\u6570\u636e\u8fdb\u884c\u52a0\u5de5\uff0c\u50cf\u7ba1\u9053\u4e00\u6837<\/li><\/ul>\n\n\n\n\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u4e3a\u4e00\u4e2a\u6570\u6307\u5b9a\u4e00\u5b9a\u987a\u5e8f\u7684\u64cd\u4f5c\uff1a\uff08ml\u9012\u5f52compose\u7248\u672c\uff09<\/p>\n\n\n\n
const compose = (f, g) => (x) => f(g(x))\nconst reduceRecursion = (arr, f, acc) => {\n if (arr.length === 0) return acc\n if (typeof acc === 'undefined') acc = arr.shift()\n const current = arr.shift()\n return reduceRecursion(arr, f, f(acc, current)) \/\/ \u6bcf\u6b21current\u90fd\u4f1a\u5148\u662fg\uff0c\u6240\u4ee5\u5148\u63a5\u53d7\u53c2\u6570\uff0c\u7136\u540e\u8fd4\u56de\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u53c8\u4f1a\u6210\u4e3a\u4e0b\u4e00\u4e2a\u51fd\u6570\u7684f\uff0c\u4e0b\u4e00\u4e2acurrent\u53c8\u4f1a\u5148\u751f\u6210\u533f\u540d\u51fd\u6570\u5148\u5f97\u5230\u53c2\u6570\u8fd0\u884c\u7ed3\u679c\u518d\u4f20\u5165f\u4e2d\n}\nreduceRecursion([x => x + 1, x => x * 2], compose)(1) \/\/ 3 \u6240\u4ee5\u8fd9\u91cc\u7684\u987a\u5e8f\u5c31\u662f\u5f97\u5230*2\u7684\u7ed3\u679c\u518d\u52a01\n\/\/ \u90a3\u4e48\u5982\u679c\u60f3\u6309\u987a\u5e8f\u5e0c\u671b\u5148\u6267\u884c+1\nconst composeOpposed = (f, g) => (x) => g(f(x))\nreduceRecursion([x => x + 1, x => x * 2], composeOpposed)(1) \/\/ 4<\/code><\/pre>\n\n\n\n\u8003\u8651\u8fd9\u4e2a\u51fd\u6570\u60f3\u52a0\u70b9\u526f\u4f5c\u7528\uff0c\u6bd4\u5982\u8bf4\u60f3\u6269\u5145\u4e00\u4e2a\u6253\u5370\u529f\u80fd<\/p>\n\n\n\n
reduceRecursion ([f => x => f(x+1), f => x => f(x*2)], compose)(console.log)(1) \/\/ 4<\/code><\/pre>\n\n\n\n\u8fd9\u91cc\u7684\u60c5\u51b5\u5c31\u4f1a\u53d1\u751f\u6539\u53d8\uff0c*2\u4f1a\u5148\u62ff\u5230console.log\uff0c\u7136\u540e\u8fd4\u56de\u533f\u540d\u51fd\u6570\uff0c+1\u4f1a\u62ff\u5230*2\u7684\u533f\u540d\u51fd\u6570\uff0c\u5f97\u5230\u5305\u542b*2\u7684\u533f\u540d\u51fd\u6570\uff0c\u7136\u540e1\u88ab\u4f20\u8fdb+1\u7684\u533f\u540d\u51fd\u6570\u91cc\u9762\u3002\u9996\u5148\u5f97\u5230+1\uff0c+1\u540e\u7684\u7ed3\u679c\u4f1a\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165*2\u7684\u533f\u540d\u51fd\u6570<\/p>\n\n\n\n