Create deepClone(obj) that correctly clones plain objects, arrays, Dates, RegExps, Maps, Sets, and handles circular references.
Skip to solutionKEEP THE
hardDSA
Implement deepClone — handle Dates, RegExp, Map, Set & circular refs
969 views
01
Understand the problem
deep-clonestructuredClonecircular
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Approach: Recursive clone with WeakMap for seen objects. Handle each built-in type, then plain object via Reflect.ownKeys.
function deepClone(obj, seen = new WeakMap()) {
if (obj === null || typeof obj !== 'object') return obj;
if (seen.has(obj)) return seen.get(obj);
if (obj instanceof Dat
Solution ready — 2 min read
Classified // press E to declassify
04
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 180 of 190 decoded in the JavaScript Coding track. One more won't hurt.