Problem, as an interviewer would state it:
"Implement pick(obj, paths) — building a genuinely NEW object containing only the specified paths (both shallow keys and nested dot-paths), matching lodash's own well-known _.pick behavior extended to support nested paths."
Examples:
pick({a:1, b:2, c:{d:3, e:4}}, ["a", "c.d"]); // {a:1, c:{d:3}}
Clarifying questions expected:
- Does this need to support NESTED dot-paths (like
"c.d"), not just shallow top-level keys? - If a specified path is genuinely missing from the source object, should it be silently skipped, or should an error be raised?
- Should the original object remain completely untouched?
Code / implementation expected: Yes — real, direct proof of both shallow and nested path selection, confirmation a genuinely missing path is silently skipped, and confirmation the original object is never mutated.