📜
Word Count
Word Count쉬움 문자열 +10pts
Problem
Write a function that counts the number of words in a string.
Examples
Input:
wordCount("Hello World")Output:
2Explanation
이 문제는 **split()과 정규표현식**을 사용하여 단어 개수를 세는 방법을 학습합니다. ## 핵심 개념: 문자열 분리와 카운팅 문자열을 단어로 분리한 후 배열의 길이를 구합니다. ### 접근 방법 ```javascript str.trim().split(/\s+/).length ``` 1. trim(): 양 끝 공백 제거 2. split(/\s+/): 하나 이상의 공백으로 분리 3. length: 배열 길이 = 단어 수 ### 정규표현식 \s+ - \s: 공백 문자 (스페이스, 탭, 줄바꿈 등) - +: 하나 이상 ``...
View detailed explanation →Key Concepts
split 메서드 정규표현식 단어 세기 빈 문자열 처리
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.