Javascript filter partial op -
the function "filter" returns array [0,4]
don't understand how gets that. can explain "partial"? built in function? i'm assuming "op" applies ">" operator numbers in array. since 5 greater 0 gets added array "result". how "partial" work?
function filter(test, array) { var result = []; foreach(array, function (element) { if (test(element)) result.push(element); }); return result; } show(filter(partial(op[">"], 5), [0, 4, 8, 12]));
in case partial takes function of 2 inputs , 1 value. call them f(x,y) , a. returns function of 1 input g(z). when call g(b) returns f(a,b). partial application. filter need functions of 1 input, while '<' 2 input function.
partial function takes function , returns function, preassignes 1 (or more) of inputs.
Comments
Post a Comment