by thomasfoster96 · 9y ago · 0 comments
Object.entries(obj).map((prop, value) => ...).reduce((newOdj, [prop, value]) => newObj[prop] = value);
I see your point about verbosity :)I like to write it this way, using as much syntax sugar as possible:
const mapObject = fn => obj => Object.assign( ...Object.entries(obj).map( ([key, value]) => ({ [key]: fn(value) }) ) );
It's not possible to say this on the internet without being rude so, apologies, but, why code like that? It genuinely was a struggle to parse (in my brain) your oneliner of code there. If I found this in our code base it would be a huge waste of time and energy.
Object.entries(obj).map(...).reduce((acc, [prop, value]) => ({...acc, prop:value}))