Problem, as an interviewer would state it:
"Implement deepMapKeys(value, fn) — recursively transforming every KEY of nested objects (including objects inside arrays) with fn, leaving values untouched."
Examples:
deepMapKeys({ a: { b: [{ c: 1 }] } }, k => k.toUpperCase());
// { A: { B: [{ C: 1 }] } }
Clarifying questions expected:
- Should keys inside objects that live inside arrays be mapped too?
- If two keys map to the same new key, which one wins?
- Which values count as "objects to descend into" — and what about a
Dateor a circular reference?
Code / implementation expected: Yes — real, direct proof at every depth, on a collision, and on a circular structure.