A higher-order function either takes a function argument and/or returns a function value. It is an important concept from the functional programming paradigm.
function map(fn, arr) {
var res = [];
for (var item of arr) {
res.push(fn(item));
}
return res;
}
map(parseInt, ['0', '1.5', -3, ''])
[0, 1, -3, NaN]
var factorThree = (val) => val * 3;
map(factorThree, [0, 1.5, -3])
[0, 4.5, -9]
function factor(num) {
return (val) => val * num;
}
map(factor(3), [0, 1.5, -3])
[0, 4.5, -9]
map(factor(4), [0, 1.5, -3])
[0, 6, -12]
The console allows you to interact with the course material and examples. Use the following keys:
A special logging function is also available: