[프로그래머스] 자바스크립트 대소문자 바꿔서 출력하기

2024. 6. 14. 18:53알고리즘

728x90
반응형

 

 

풀이 

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

let input;

rl.on('line', (line) => {
  input = [...line];
}).on('close', () => {
  console.log(
    input.map((char) => (/[a-z]/.test(char) ? char.toUpperCase() : char.toLowerCase())).join(''),
  );
});

 

/패턴/.test(문자열)

문자열이 /패턴/ 이라는 정규표현식과 매칭되는지 여부를 검사하여 true나 false를 반환합니다.

 

배열.join(구분자)

배열의 각 요소를 지정한 구분자로 연결해 하나의 문자열로 만들어 반환합니다.

728x90
반응형