코딩 테스트/프로그래머스 - 자바스크립트
프로그래머스 LV.0 대문자와 소문자
ctrs
2023. 9. 17. 01:28
프로그래머스 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;
}