How do I create a utility function that creates a new object by recursively 'cloning' an object and applying a function to its keys/values/index? (Much like the solution here, but for deep nested objects: map function for objects (instead of arrays))
const light = {
a: 'light-a',
b: {
b1: 'light-b1',
b2: 'light-b2'
}
}
const dark = {
a: 'dark-a',
b: {
b1: 'dark-b1',
b2: 'dark-b2'
}
}
// const deepMapObjectFunction = () => ...
const lightAndDark = deepMapObjectFunction(light, (key, value index) => ({
light: value,
dark: dark[key],
}))
console.log(lightAndDark)
/*
{
a: { light: 'light-a', dark: 'dark-a'},
b: {
b1: {
light: 'light-b1',
dark: 'dark-b1',
},
b2: {
light: 'light-b2',
dark: 'dark-b2',
},
}
}
*/