列表

详情


FED60. 二次封装函数

描述

已知函数 fn 执行需要 3 个参数。请实现函数 partial,调用之后满足如下条件:
1、返回一个函数 result,该函数接受一个参数
2、执行 result(str3) ,返回的结果与 fn(str1, str2, str3) 一致

示例1

输入:

var sayIt = function(greeting, name, punctuation) {     return greeting + ', ' + name + (punctuation || '!'); };  partial(sayIt, 'Hello', 'Ellie')('!!!');

输出:

Hello, Ellie!!!

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 840ms, 内存消耗: 77772KB, 提交时间: 2021-03-15

{"css":"","js":"function partial(fn, str1, str2) {\n    return function result(str3) {\n        return fn.bind(null, str1, str2, str3)()\n    }\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 842ms, 内存消耗: 77772KB, 提交时间: 2021-07-18

{"css":"","js":"function partial(fn, str1, str2) {\n    return (str3) => fn(str1,str2,str3)\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 842ms, 内存消耗: 77772KB, 提交时间: 2020-11-21

{"css":"","js":"function partial(fn, str1, str2) {\n\tvar f = function(s){\n        return fn(str1,str2,s);\n    }\n    return f;\n}\n","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 843ms, 内存消耗: 77772KB, 提交时间: 2021-06-28

{"css":"","js":"function partial(fn, str1, str2) {\nreturn function result(str3){\n    return fn(str1,str2,str3)\n}\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 843ms, 内存消耗: 77772KB, 提交时间: 2021-05-23

{"css":"","js":"function partial(fn, str1, str2) {\n    return function result(str3) {\n        return fn(str1,str2,str3)\n    }\n}","html":"","libs":[]}

上一题