Deep Clone an Object
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write deepClone(value), returning a copy that shares no objects with the original, so changing the copy at any depth leaves the original alone. Copy plain objects and arrays at every depth, and copy each Date as a new Date with the same time. Return primitives and functions as they are. The input never contains cycles, but it can be large: cloning an array of 100,000 small objects must be quick. Don't change the input.
Your code must pass
- Copies primitives as they are
- Copies nested objects and arrays, sharing none of them
- Copies Dates as new Dates with the same time
- Keeps functions as they are
- Is fast enough for 100,000 objects