Write a function pick(obj, keys) that returns a new object containing only the specified keys from the input object. If a specified key does not exist on obj, ignore it. For example, pick({ a: 1, b: 2, c: 3 }, ['a', 'c', 'z']) should return { a: 1, c: 3 }.
function pick(obj, keys) {
// Your code here
}
Rules:
- Do not mutate the original object.
- Ignore keys from the array that do not exist on the object.
- Return a new object with the matching key-value pairs.
Post your solution as a reply. Answer goes up in about a day.