📦

Deep Clone

Deep Clone
어려움 객체 +40pts

Problem

Write a function that creates a deep clone of an object.

Examples

Input: deepClone({ a: 1, b: { c: 2 } })
Output: { a: 1, b: { c: 2 } }
💡 새 객체는 원본과 독립적입니다.

Explanation

이 문제는 **얕은 복사 vs 깊은 복사**의 차이를 이해하고, 재귀를 통한 깊은 복사를 구현합니다. **얕은 복사(Shallow Copy)의 문제** `const copy = {...obj}`는 1단계만 복사합니다: ```javascript const original = { a: 1, b: { c: 2 } }; const shallow = {...original}; shallow.b.c = 99; // original.b.c도 99로 변경됨! ``` **깊은 복사(Deep Copy)가 필요한 이유** 중첩된 객체까지 완전히 ...

View detailed explanation →

Key Concepts

깊은 복사 vs 얕은 복사 재귀적 객체 순회 typeof 연산자 hasOwnProperty 메서드
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.