Write a function to perform a deep clone of an object.
HardProblem Statement
Write a function to perform a deep clone of an object.
Sample Input
{ name: "John", age: 30, details: { city: "New York", skills: ["TypeScript", "JavaScript"] } }Sample Output
Original: {
name: 'John',
age: 30,
details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}
Clone: {
name: 'John',
age: 30,
details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
function deepClone<T>(obj: T): T {
// Your logic here
}
Input
{ name: "John", age: 30, details: { city: "New York", skills: ["TypeScript", "JavaScript"] } }Expected Output
Original: {
name: 'John',
age: 30,
details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}
Clone: {
name: 'John',
age: 30,
details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}