pick and omit build a subset of an object. pick keeps only the keys you name; omit drops them and keeps the rest — they're complements. Their By variants, pickBy and omitBy, select by a predicate over each value instead of by a fixed key list. Together they're how you trim an object down to the fields you actually want.
Implement all four. pick(obj, keys) and omit(obj, keys) take an array of keys; pickBy(obj, predicate) and omitBy(obj, predicate) take a function called with (value, key). Each returns a new object without mutating the input.
function pick(obj, keys) {} // keep the listed keys
function omit(obj, keys) {} // drop the listed keys
function pickBy(obj, predicate) {} // keep where predicate(value, key) is truthy
function omitBy(obj, predicate) {} // keep where predicate(value, key) is falsy
pick({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { a: 1, c: 3 }
omit({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { b: 2 }
pickBy({ a: 1, b: 2, c: 3 }, (v) => v > 1); // { b: 2, c: 3 }
omitBy({ a: 0, b: 1, c: '' }, Boolean); // { a: 0, c: '' }
pick and omit are complements — pick keeps what you name, omit keeps everything else.pickBy/omitBy predicate — receives (value, key); pickBy keeps truthy results, omitBy keeps falsy ones (they're inverses).The full solution is part of Premium
Walkthrough, edge cases, complexity notes, and the runnable editor unlock with a Premium subscription.
Submissions are part of Premium
Unlock community code, comments, reactions, and framework-specific approaches.
pick and omit build a subset of an object. pick keeps only the keys you name; omit drops them and keeps the rest — they're complements. Their By variants, pickBy and omitBy, select by a predicate over each value instead of by a fixed key list. Together they're how you trim an object down to the fields you actually want.
Implement all four. pick(obj, keys) and omit(obj, keys) take an array of keys; pickBy(obj, predicate) and omitBy(obj, predicate) take a function called with (value, key). Each returns a new object without mutating the input.
function pick(obj, keys) {} // keep the listed keys
function omit(obj, keys) {} // drop the listed keys
function pickBy(obj, predicate) {} // keep where predicate(value, key) is truthy
function omitBy(obj, predicate) {} // keep where predicate(value, key) is falsy
pick({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { a: 1, c: 3 }
omit({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { b: 2 }
pickBy({ a: 1, b: 2, c: 3 }, (v) => v > 1); // { b: 2, c: 3 }
omitBy({ a: 0, b: 1, c: '' }, Boolean); // { a: 0, c: '' }
pick and omit are complements — pick keeps what you name, omit keeps everything else.pickBy/omitBy predicate — receives (value, key); pickBy keeps truthy results, omitBy keeps falsy ones (they're inverses).The full solution is part of Premium
Walkthrough, edge cases, complexity notes, and the runnable editor unlock with a Premium subscription.
Submissions are part of Premium
Unlock community code, comments, reactions, and framework-specific approaches.
Unlock the solution & editor
Runnable editor + tests
Solve in the browser with instant Jest feedback.
Detailed solutions
Walkthroughs, edge cases, and complexity notes.
Multi-framework variants
React, Vue, Vanilla, Angular — same question, different stacks.