Title Case
Title Case - Explanation
Problem Summary
Write a function that capitalizes the first letter of each word.
Go to Problem →Detailed Explanation
이 문제는 **split, map, join**을 조합하여 제목 형식(Title Case)으로 변환하는 방법을 학습합니다. ## 핵심 개념: 문자열 변환 파이프라인 여러 문자열 메서드를 체이닝하여 복잡한 변환을 수행합니다. ### 접근 방법 ```javascript str.split(' ') .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(' ') ``` ### 단계별 분석 1. split(' '): 공백으로 단어 분리 2. map: 각 단어 변환 - charAt(0).toUpperCase(): 첫 글자 대문자 - slice(1).toLowerCase(): 나머지 소문자 3. join(' '): 공백으로 다시 연결 ### 실행 예시 ```javascript "hello WORLD" → ["hello", "WORLD"] → ["Hello", "World"] → "Hello World" ``` ### 주의사항 - 빈 단어(연속 공백)가 있으면 오류 가능 - 특수한 단어(a, an, the 등)는 일반적으로 소문자로 유지 - 더 정교한 타이틀 케이스는 라이브러리 사용 권장
Solution Code
function titleCase(str) {
return str.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
}Key Concepts from This Problem
Common Mistakes
Hints
Complexity Analysis
Time Complexity
O(n)
Grows linearly with input size
Space Complexity
O(n)
Uses memory proportional to input size