FED56. 函数传参
描述
将数组 arr 中的元素作为调用函数 fn 的参数示例1
输入:
function (greeting, name, punctuation) {return greeting + ', ' + name + (punctuation || '!');}, ['Hello', 'Ellie', '!']
输出:
Hello, Ellie!
HTML/CSS/JavaScript 解法, 执行用时: 856ms, 内存消耗: 77772KB, 提交时间: 2020-12-14
{"css":"","js":"function argsAsArray(fn, arr) {\n return fn.apply(fn, arr);\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 856ms, 内存消耗: 77804KB, 提交时间: 2020-11-18
{"css":"","js":"function argsAsArray(fn, arr) {\n return fn(arr[0],arr[1],arr[2]);\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 856ms, 内存消耗: 77844KB, 提交时间: 2020-11-23
{"css":"","js":"function argsAsArray(fn, arr) {\n return fn(...arr)\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 860ms, 内存消耗: 77868KB, 提交时间: 2021-05-24
{"css":"","js":"function argsAsArray(fn, arr) {\n return fn.apply(null, arr)\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 861ms, 内存消耗: 77772KB, 提交时间: 2021-07-18
{"css":"","js":"function argsAsArray(fn, arr) {\n return fn.apply(fn,arr)\n}","html":"","libs":[]}