프로그래머스(JavaScript)/Lv0

[프로그래머스 : 코딩 기초 트레이닝Lv0. 대소문자 바꿔서 출력하기(JavaScript)

지미지민 2024. 3. 27. 22:47

 

 

 

💜 코드


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].split('').map((v) => v === v.toUpperCase() ? v.toLowerCase() : v.toUpperCase());
    
    console.log(str.join(''));
});

 

 

 

💜 실행 결과


 

 

 

💜 다른 사람의 풀이


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].split('');
    str.forEach((value, index) => {
        if (value === value.toUpperCase()) {
            str[index] = value.toLowerCase();
        } else {
            str[index] = value.toUpperCase();
        }
    });
    console.log(str.join(''));
});