#7MediumJavaScript functions
7. deepOmit
JavaScript
Implement deepOmit(val, keys) to recursively remove all specified keys from nested objects and arrays without mutating the original.
Example 1:
deepOmit({ a: 1, b: { c: 2, d: 3 } }, ["c"]);
// { a: 1, b: { d: 3 } }solution.js
Omits keys at nested levels without mutating input
(() => {
const input = { a: 1, b: { c: 2, d: [{ c: 3, e: 4 }] } };
const res = deepOmit(input, ["c"]);
expect(res).toEqual({ a: 1, b: { d: [{ e: 4 }] } });
expect(input.b.c).toBe(2);
})()