Building with small pieces
map, filter and addEventListener all take functions. A function that takes or returns another function is a higher-order function. With them you can build new behaviour by snapping small functions together.
Writing your own
function myMap(list, fn) {
const out = [];
for (const item of list) out.push(fn(item));
return out;
}
console.log(myMap([1, 2, 3], (n) => n * 10));
const not = (fn) => (...args) => !fn(...args);
const isEven = (n) => n % 2 === 0;
console.log([1, 2, 3, 4].filter(not(isEven)));