Skip to content

Commit 70a578c

Browse files
committed
[충돌해결] Part1 5.3 ucfirst
1 parent 71ab899 commit 70a578c

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

1-js/05-data-types/03-string/1-ucfirst/solution.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ let newStr = str[0].toUpperCase() + str.slice(1);
88

99
그런데 이렇게 코드를 작성하면 `str`이 비어있는 문자열인 경우 `str[0]``undefined`가 되는 문제가 발생합니다. `undefined``toUpperCase()`메서드를 지원하지 않으므로 에러가 발생하죠.
1010

11-
<<<<<<< HEAD
12-
두 가지 방법을 사용해 이런 예외사항을 처리 할 수 있습니다.
13-
14-
1. `str.charAt(0)``str`이 비어있는 문자열이더라도 항상 문자열을 반환하므로, 이 메서드를 사용합니다.
15-
2. 빈 문자열인지를 확인하는 코드를 작성합니다.
16-
17-
두 번째 방법을 사용하여 작성한 답안은 아래와 같습니다.
18-
=======
19-
The easiest way out is to add a test for an empty string, like this:
20-
>>>>>>> upstream/master
11+
가장 간단한 해결 방법은 아래처럼 빈 문자열인지 확인하는 조건을 추가하는 것입니다.
2112

2213
```js run demo
2314
function ucFirst(str) {
@@ -27,4 +18,4 @@ function ucFirst(str) {
2718
}
2819

2920
alert( ucFirst("john") ); // John
30-
```
21+
```

0 commit comments

Comments
 (0)