All Challenges
2 PointsBasicJavaScript Core
00:00
Enterprise Deep Clone Engine with Circular Reference & Type Preservation
Implement a complete recursive deep clone engine handling circular object graphs, TypedArrays, Sets, Maps, and Symbol keys.
### Problem Overview
Standard `JSON.parse(JSON.stringify(obj))` fails on circular references, drops `undefined`, `Function`, `Symbol` keys, and corrupts `Date`, `RegExp`, `Map`, `Set`, and `TypedArray` instances.
Your task is to build a robust deep clone utility that creates an isolated deep copy of any complex JavaScript data structure.
### Functional Requirements
1. **Circular Reference Handling**:
- Detect cyclic graphs and preserve the exact internal reference topology without stack overflows.
2. **Standard & Special Types Support**:
- `Date` & `RegExp` (preserve flags and source).
- `Map` (deep clone keys and values).
- `Set` (deep clone elements).
- `ArrayBuffer`, `Uint8Array`, `Float32Array` etc.
3. **Symbol Keys & Property Descriptors**:
- Preserve non-enumerable properties and `Symbol` keys.
- Preserve prototype chain inheritance (`Object.create(proto)`).
### Non-Functional Requirements
- **Performance**: Use `WeakMap` for reference caching to ensure (O(N)) time complexity.
- **Memory Footprint**: Do not leak memory across clone operations.
AI Review Rubric Dimensions (1–10 Points):
- WeakMap cyclic reference detection
- Special built-in types support
- Symbol and prototype inheritance
- Stack safety
solution.tsTYPESCRIPT
1
2
3
4
5
6
7
8
9
10
10 lines•271 characters•
AI Review Ready