코딩테스트 문제풀이/inflearn

[인프런] Node.js / 섹션1 - 기본문제 풀이 / 13. 대소문자 변환

sangchu 2023. 1. 4. 16:16

대문자는 소문자로 소문자는 대문자로 변환하여 출력

 

나의 풀이

function solution(s) {
  let answer = "";
  for (let x of s) {
    if (x === x.toUpperCase()) {
      answer += x.toLowerCase();
    } else {
      answer += x.toUpperCase();
    }
  }
  return answer;
}

console.log(solution("StuDY"));