Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function that deep clones an object, including nested objects and arrays.

Hard

Problem Statement

Create a function that deep clones an object, including nested objects and arrays.

Sample Input

{
 a: 1,
 b: [ 1, 2, 3 ],
 c: { d: 4, e: 5 } }

Sample Output

{ a: 1, b: [ 1, 2, 3 ], c: { d: 4, e: 5 } }

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Deep clone an object, including nested structures function deepClone(obj) { // Check if the value is not an object or is null, return it // If it is an array, map each element using deepClone // For an object, iterate and deepClone each property } const original = { a: 1, b: [ 1, 2, 3 ], c: { d: 4, e: 5 } }; const cloned = deepClone(original); console.log(cloned);
Log in or sign up to run or submit your code.Log inSign up
Input
{
 a: 1,
 b: [ 1, 2, 3 ],
 c: { d: 4, e: 5 } }
Expected Output
{ a: 1, b: [ 1, 2, 3 ], c: { d: 4, e: 5 } }