Objects & Recursion
Deep Clone Object
mediumJS / TS
Problem Statement
Write a function `deepClone(obj)` that returns a deep copy of an object or array, handling primitives, nested objects, arrays, and dates without using `structuredClone` or `JSON.parse(JSON.stringify(obj))`.
Examples
Example:
const original = { a: 1, b: { c: 2 } };
const copy = deepClone(original);
copy.b.c = 42;
console.log(original.b.c); // 2Includes TypeScript & JavaScript starter code
Start Interview with this Problem