카테고리 없음

[JavaScript/자바스크립트] 프로그래머스 Level.0 - 대소문자 바꿔서 출력하기

코코월드주인장 2023. 5. 22. 16:24

🐳 문제 설명

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

🐳 제한 조건

  • 1 ≤ str의 길이 ≤ 20

🐳 입출력 예

입력 #1

aBcDeFg

출력 #1

AbCdEfG

🐳 작성 솔루션

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];
    result = [];
    const strValue = [...str]
    strValue.map(a => {
        if(a === a.toUpperCase()) {
            result.push(a.toLowerCase());
        }else {
            result.push(a.toUpperCase());
        }
    })
    console.log(result.join(''));
});