저장을 습관화
프로그래머스 LV.0 대문자와 소문자 본문
프로그래머스 LV.0 대문자와 소문자
https://school.programmers.co.kr/learn/courses/30/lessons/120893
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 명
대문자와 소문자
2. 문제 설명
문자열 my_string이 매개변수로 주어질 때, 대문자는 소문자로 소문자는 대문자로 변환한 문자열을 return하도록 solution 함수를 완성해주세요.
3. 제한 사항
- 1 ≤ my_string의 길이 ≤ 1,000
- my_string은 영어 대문자와 소문자로만 구성되어 있습니다.
4. 예시
my_string | result |
"cccCCC" | "CCCccc" |
a | s |
5. 기본 제공 코드
function solution(my_string) {
var answer = '';
return answer;
}
6. 제출한 내 답
const solution = (my_string) => {
return my_string
.split("")
.map((a) => {
return a === a.toLowerCase() ? a.toUpperCase() : a.toLowerCase();
})
.join("");
};
6-2. VSC에 작성한 내용
const solution = (my_string) => {
return my_string
.split("")
.map((a) => {
return a === a.toLowerCase() ? a.toUpperCase() : a.toLowerCase();
})
.join("");
};
// 테스트
console.log(solution("cccCCC"));
console.log(solution("abCdEfghIJ"));
7. 특이사항
없음
8. 다른 사람이 작성한 답
8-1. for of 문
function solution(my_string) {
var answer = '';
for (let c of my_string) answer += c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase();
return answer;
}
'코딩 테스트 > 프로그래머스 - 자바스크립트' 카테고리의 다른 글
프로그래머스 LV.0 암호 해독 (0) | 2023.09.17 |
---|---|
프로그래머스 LV.0 순서 바꾸기 (0) | 2023.09.17 |
프로그래머스 LV.0 개미 군단 (0) | 2023.09.17 |
프로그래머스 LV.0 l로 만들기 (0) | 2023.09.17 |
프로그래머스 LV.0 원하는 문자열 찾기 (0) | 2023.09.16 |