Problem, as an interviewer would state it:
"Create flattenObject(obj) producing { "a.b.0.c": value } from a nested object, and unflattenObject to reverse it. Support arrays and escaping."
Examples:
flattenObject({ a: { b: [{ c: 1 }] } }); // { "a.b.0.c": 1 }
unflattenObject({ "a.b.0.c": 1 }); // { a: { b: [{ c: 1 }] } }
Clarifying questions expected:
- How should a key that itself contains a dot be represented so it survives the round trip?
- Should numeric path segments rebuild real arrays on the way back?
- What about empty objects and arrays,
nullleaves, and untrusted input paths like__proto__.x?
Code / implementation expected: Yes — real, direct proof of a full round trip, of dotted keys, and of the safety guard.