Omit Object Keys

EasyUtility Functions10 min4 tests

Implement an omit function that creates a new object without the specified keys.

Requirements

  • Return a new object with all keys except the ones listed
  • Ignore keys that don't exist on the source object
  • Do not mutate the original object

Example

omit({ a: 1, b: 2, c: 3 }, ['b']);    // { a: 1, c: 3 }
omit({ x: 10, y: 20, z: 30 }, ['y', 'z']); // { x: 10 }
Hints (3)
  1. Create a new object to hold the result.
  2. Convert the keys array to a Set for efficient lookups.
  3. Iterate over the source object keys and include only those not in the Set.

Topics

  • Utility Functions

Asked at

Amazon · Uber · Stripe

Join Us
blur