Pick and Omit Keys

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write pick(obj, keys) and omit(obj, keys), where obj is a plain object and keys is an array of key names. pick returns a new object with only the listed keys that obj has as its own properties: a listed key obj doesn't have is left out, but one it has with the value undefined is kept. omit returns a new object with every own key of obj except the listed ones. Neither changes obj, and both copy the values across as they are (a shallow copy).

Your code must pass

  • pick keeps only the listed keys
  • pick leaves out keys the object doesn't have
  • omit drops the listed keys
  • Neither changes the original object