The "filter" function returns an array [0,4], but I do not understand how this is obtained. Can you explain the "partial"? Is this a built-in function? I assume that "op" applies the ">" operator to numbers in the array. Since 5 is greater than 0, it is added to the result array. But how does "partial" work 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]));
source
share