Deep Freeze
EasyP3Coding
Implement deepFreeze(value), which freezes an object and everything reachable through its properties, then returns the same object.
- Freeze nested objects and arrays at any depth (own properties, string and symbol keyed).
- Return
valueitself, not a copy. - Primitives are returned as they are.
- The structure may contain cycles (an object that refers back to an ancestor); the function must terminate.
- Do not freeze anything that is not reached through own properties; prototypes are left alone.
Example 1
- Input
- const o = deepFreeze({ a: { b: 1 } }); Object.isFrozen(o.a);
- Output
- true
Constraints
- Total number of objects <= 10^4
- Values are plain objects and arrays, with possible cycles.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.