FED64. 柯里化
描述
已知 fn 为一个预定义函数,实现函数 curryIt,调用之后满足如下条件:示例1
输入:
var fn = function (a, b, c) {return a + b + c}; curryIt(fn)(1)(2)(3);
输出:
6
HTML/CSS/JavaScript 解法, 执行用时: 869ms, 内存消耗: 77900KB, 提交时间: 2020-12-21
{"css":"","js":"function curryIt(fn) {\n return function a(x1){\n return function b(x2){\n return function c(x3){\n return fn(x1, x2, x3);\n }\n }\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 874ms, 内存消耗: 77860KB, 提交时间: 2020-11-21
{"css":"","js":"function curryIt(fn) {\n return function a(ele){\n a.length = 1\n return function b(ele1){\n b.length =1\n return function c(ele2){\n c.length=1\n return fn(ele,ele1,ele2)\n }\n }\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 876ms, 内存消耗: 77900KB, 提交时间: 2020-11-21
{"css":"","js":"\n\nfunction curryIt(fn) {\n var length = fn.length,\n args = [];\n var result = function (arg){\n args.push(arg);\n length --;\n if(length <= 0 ){\n return fn.apply(this, args);\n } else {\n return result;\n }\n }\n \n return result;\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 876ms, 内存消耗: 77948KB, 提交时间: 2020-11-08
{"css":"","js":"function curryIt(fn) {\n return function a(x1) {\n return function b(x2) {\n return function c(x3) {\n return x1+x2+x3;\n }\n }\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 877ms, 内存消耗: 77880KB, 提交时间: 2020-11-23
{"css":"","js":"function curryIt(fn) {\n return function(a) {\n return function(b) {\n return function(c) {\n return a * b * c\n }\n \n }\n }\n}","html":"","libs":[]}