DEV Community

Discussion on: Invert object with Lodash

Collapse
 
alexstaroselsky profile image
Alexander Staroselsky • Edited

Lodash has some interesting features. What do you see as a valid use case for this function? Also here is an oversimplified pure JS version of _.invert:

const invert = (o) =>
  Object.entries(o).reduce(
    (acc, [key, value]) => ({ ...acc, [value]: key }),
    {}
  );

Enter fullscreen mode Exit fullscreen mode
Collapse
 
tomaszs2 profile image
Tom Smykowski

Nice vanilla code,
I use it mostly with data transformations