File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ // map()으로 풀이
2
+ function solution(myString) {
3
+ return [...myString].map((e) => e == 'a' || e == 'A' ? 'A' : e.toLowerCase()).join("");
4
+ }
5
+
6
+
7
+ // // for문으로 풀이
8
+ function solution(myString) {
9
+ var answer = '';
10
+ for (let i = 0; i < myString.length; i++) {
11
+ if (myString[i] == 'a' || myString[i] == 'A') {
12
+ answer += myString[i].toUpperCase();
13
+ } else if (myString[i] !== 'a') {
14
+ answer += myString[i].toLowerCase();
15
+ }
16
+ }
17
+
18
+ return answer;
19
+ }
20
+
21
+ // for문으로 풀이 한 뒤 test 3번에서 오류가 났다. 조건을 다시 살펴보니
22
+ // '"A"가 아닌 모든 대문자 알파벳은 소문자 알파벳으로 변환하여 return'이라는 설명이 있는 것을 확인했다.
23
+ // 조건에 맞게 || myString[i] == 'A'를 추가해주었다.
24
+
25
+
26
+ // 다른 사람의 풀이 1
27
+ function solution(myString) {
28
+ // ['a', 'A'].includes(str)를 통해 배열에 특정 요소('a', 'A')가 포함되어 있는지를 확인.
29
+ return [...myString].map(str => ['a', 'A'].includes(str) ? 'A' : str.toLowerCase()).join('');
30
+ }
31
+
32
+ // 다른 사람의 풀이 2
33
+ // 1. s.toLowerCase()를 통해 모든 문자를 소문자로 통일
34
+ // .replaceAll('a', 'A')로 변환된 소문자 문자열에서 모든 'a'를 'A'로 대체
35
+ const solution = s => s.toLowerCase().replaceAll('a','A');
You can’t perform that action at this time.
0 commit comments