EasyPythonJavaScriptTypeScript

Pick Keys

ObjectsFunctions

Implement solve(obj, keys) that returns a new object containing only the
specified keys (similar to Lodash _.pick). Missing keys are silently ignored.

Examples

  • solve({ a:1, b:2, c:3 }, ['a','c']){ a:1, c:3 }
  • solve({ x:10 }, ['y']){}

Constraints

  • Don't mutate the original object.
  • Return a plain object (no prototype chain tricks).

Sample tests

Test #1Pick two of three keys
Input: [{"a":1,"b":2,"c":3},["a","c"]]
Output: {"a":1,"c":3}
Test #2Missing key → empty result
Input: [{"x":10},["y"]]
Output: {}
Test #3Object with string values
Input: [{"age":30,"name":"Alice","role":"admin"},["name","role"]]
Output: {"name":"Alice","role":"admin"}
Test #4Empty keys list → empty result
Input: [{"a":1,"b":2},[]]
Output: {}
Test #5Extra non-existent key is silently ignored
Input: [{"a":1,"b":2,"c":3},["a","b","c","d"]]
Output: {"a":1,"b":2,"c":3}