* Implement function Makeclosures, after the call satisfies the following conditions:
1. Returns a function array result with the same length as arr
2. Run the first function in result, i.e. result[i] (), the result is the same as FN (Arr[i])
Input
[1, 2, 3], function (x) {return x * x;}
function Makeclosures (arr, fn) { var result = []; for (var i = 0; i < arr.length; i++) { (function (i) { Result.push (function () { return fn (Arr[i]); }); }) (i); } return result;} var arr = [1, 2, 3];var fn = function (x) {return x * x;} var result = Makeclosures (arr, FN); Console.log (result); [F,f, F, F]console.log (Result[1] ()); 4console.log (FN (arr[1])); 4
The known function fn execution requires 3 parameters. Implement the partial function, which satisfies the following conditions:
1. Returns a function result, which takes a parameter
2. Execution result (STR3), the returned result is consistent with FN (STR1, str2, STR3)
Input:var sayit = function (greeting, name, punctuation) {return greeting + ', ' + name + (Punctuation | | ‘!‘); }; Partial (sayit, ' Hello ', ' Ellie ') ('!!! ');
Output:hello, Ellie!!!
function partial (FN, str1, str2) {return function (STR3) {return fn (str1, str2, STR3);}} var sayit = function (greeting, name, punctuation) {return greeting + ', ' + name + (Punctuation | | ‘!‘);}; Console.log (Partial (sayit, ' Hello ', ' Ellie ') ('!!! '));
JavaScript closure closure