cf.completefrontend

Write the codeEasy

Write pick(obj, keys) and omit(obj, keys).

Both take an object, obj, and an array of property names, keys, and return a new object. Neither may change obj.

pick keeps only the listed keys that obj has as its own properties. A listed key that obj doesn't have, or only inherits, is left out.

omit keeps every own enumerable key of obj except the listed ones.

Write this
function pick(obj, keys) {
  // your code
}
 
function omit(obj, keys) {
  // your code
}
 
// const user = { id: 1, name: "Ada", password: "x" };
// pick(user, ["id", "name"]);  // { id: 1, name: "Ada" }
// pick(user, ["id", "email"]); // { id: 1 }: user has no email
// omit(user, ["password"]);    // { id: 1, name: "Ada" }
// user;                        // { id: 1, name: "Ada", password: "x" }: unchanged

Solve it in the editor, with tests

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…