📚

Flatten Deep

Flatten Deep
어려움 배열 +40pts

Problem

Write a function that flattens a nested array to any depth.

Examples

Input: flattenDeep([1, [2, [3, [4]]]])
Output: [1, 2, 3, 4]

Explanation

이 문제는 **재귀와 Array.isArray**를 사용하여 중첩 배열을 완전히 평탄화하는 방법을 학습합니다. ## 핵심 개념: 깊은 평탄화 모든 중첩 수준을 재귀적으로 평탄화합니다. ### 구현 ```javascript function flattenDeep(arr) { return arr.reduce((flat, item) => flat.concat(Array.isArray(item) ? flattenDeep(item) : item), []); } ``` ### 동작 원리 1. 각 요소가 배열인지 확인 2. 배열...

View detailed explanation →

Key Concepts

재귀 Array.isArray 깊은 평탄화 reduce
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.