Last active
February 3, 2020 10:37
-
-
Save mmontes11/222e8492dc27bc4fc691adfefaa9191b to your computer and use it in GitHub Desktop.
Maps object values recursivelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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