cloneObject

Easy · Object Manipulation · 2 test cases

Create a shallow clone of an object. A shallow clone means that the new object is a copy of the top-level properties of the original object.

Examples

cloneObject({a: 1, b: {c: 2}}) → {a: 1, b: {c: 2}}

Starter code

function cloneObject(obj) {

}

Complexity of the optimal solution

Time O(n), space O(n). The spread syntax creates a new object and copies all 'n' enumerable properties from the original object. The time and space are proportional to the number of properties.

Solve cloneObject in the browser