Problem, as an interviewer would state it:
"Implement set(obj, path, value) — writing a value at a deeply nested path, automatically CREATING any missing intermediate objects (or arrays, for numeric path segments) along the way, matching lodash's own well-known _.set behavior."
Examples:
set({}, "a.b.c", 42); // {a: {b: {c: 42}}}
Clarifying questions expected:
- Does this need to CREATE missing intermediate objects, or only update a path that already fully exists?
- Should a numeric path segment (like
"a[0].b") create a real ARRAY at that level, not a plain object with a"0"key? - Does this mutate the original object in place, or return a genuinely new one?
Code / implementation expected: Yes — real, direct proof of missing-intermediate-object creation, correct updates to an already-existing deep path, and correct array creation for a numeric path segment.