Skip to content

Instantly share code, notes, and snippets.

@mmontes11
Last active February 3, 2020 10:37
Show Gist options
  • Save mmontes11/222e8492dc27bc4fc691adfefaa9191b to your computer and use it in GitHub Desktop.
Save mmontes11/222e8492dc27bc4fc691adfefaa9191b to your computer and use it in GitHub Desktop.
Maps object values recursivelly
const mapObjectValues = (value, shouldMap, mapFn, ...args) => {
if (shouldMap(value)) {
return mapFn(value, ...args);
}
return {
...Object.keys(value).reduce(
(acc, k) => ({
...acc,
[k]: mapObjectValues(value[k], shouldMap, mapFn, ...args),
}),
{},
),
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment