Problem, as an interviewer would state it:
"Implement get(obj, path, defaultValue) — safely reading a deeply nested value from an object via a dot-notation (or array-bracket) path string, returning defaultValue if any part of the path is genuinely missing, matching lodash's own well-known _.get behavior."
Examples:
get({a: {b: {c: 42}}}, "a.b.c"); // 42
get({a: 1}, "x.y.z", "fallback"); // "fallback"
Clarifying questions expected:
- Does the path need to support BOTH dot notation (
"a.b.c") AND array-bracket notation ("a[0].b"), or just one format? - If the actual value at the path is a genuine FALSY value (like
0,false, or an empty string), should the default still correctly NOT be used? - Should the path also be acceptable as a pre-split array of keys, not just a string?
Code / implementation expected: Yes — real, direct proof of correct dot/bracket path access, correct fallback on a genuinely missing path, and — critically — confirmation a genuine falsy value at the path is correctly returned, not confused with "missing."