An array mapping function in lodash

Viewed 556

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.

2 Answers
Related