I've seen lots of solutions for "deep mapping" over an object to change either the keys of the object, or the value of the object, but not both.
For example if given the following object:
const obj = {
this: {
is_not: {
something: "we want to keep"
},
is: {
a: {
good_idea: 22
},
b: {
bad_idea: 67
},
c: [{
meh_idea: 22
}]
}
}
}
Essentially I'd like to be able to transform it with the following function signature:
const newObj = deepTransform(obj, iterator)
function iterator (key, value) {
if (key.endsWith("idea")) return { [key.replace("idea", "")]: value + 1}
else if (key === "is_not") return {}
else return {[key]: value}
}
Running deepTransform would result in an object that looks like:
{
this: {
is: {
a: {
good: 23
},
b: {
bad: 68
},
c: [{
meh: 23
}]
}
}
}
If anyone could help me create this function that would be awesome! I'd be more than happy if it used lodash functions under the hood.
Please ask if anything is unclear. Thanks!