대소문자 바꿔서 출력하기

도비김·2023년 6월 29일
0
문제 설명

영어 알파벳으로 이루어진 문자열 str이 주어집니다. 각 알파벳을 대문자는 소문자로 소문자는 대문자로 변환해서 출력하는 코드를 작성해 보세요.


제한사항
  • 1 ≤ str의 길이 ≤ 20
    • str은 알파벳으로 이루어진 문자열입니다.

입출력 예

입력 #1

aBcDeFg

출력 #1

AbCdEfG

※2023년 05월 03일 제한사항이 수정되었습니다.

solution

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = [line];
}).on('close',function(){
    str = input[0];
    const splitedStr = [...str];
    const result = splitedStr.map(a => {
     const curCodeAt = a.charCodeAt()
     if (curCodeAt>=97) return a.toUpperCase()
        return a.toLowerCase()
    })
    console.log(result.join(''))
});

블로그 검색찬스 ㅎㅎ;;

기존 input을 나눠 복사해서 charCodeAt으로 숫자화 된 문자열을 map으로 대소문자를 바꿔준뒤 join으로 묶어준다.

profile
To Infinity, and Beyond!

0개의 댓글