I have this chunk of javascript code:
function arrayMapper(mappingFunc) {
return items => items.map(mappingFunc);
}
function fooTransformer(tem) {
return (...); // do something with item and returns a value
}
function barTransformer(tem) {
return (...); // do something with item and returns a value
}
const foosTransformer = arrayMapper(fooTransformer);
const barsTransformer = arrayMapper(barTransformer);
(...)
foosTransformer([1, 2, 3]);
I was wondering if something like my arrayMapper function would exist natively in something like lodash, just to avoid reinventing the wheel.
arrayMapperfunction is just a wrapper for the nativeArray.prototype.mapfunction, so what's even the point of it?arrayMapperfunction, I could use :const foosTransformer = items => items.map(fooTransformer);directly... it's just that I have 5 or 6 functions like that.