티스토리 뷰

https://school.programmers.co.kr/learn/courses/30/lessons/120893

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 


 

Ascii 코드 이용

function solution(my_string) {
    return my_string.split("").map((str) => {
        const ascii = str.charCodeAt(0)
        if(ascii >= 65 && ascii <= 90) {
            return str.toLowerCase()
        } else if(ascii >= 97 && ascii <= 122) {
            return str.toUpperCase()
        }
    }).join("")
}

my_string은 대소문자 외에 다른 문자는 없으므로 아래와 같이 가능

function solution(my_string) {
    return my_string.split("").map((str) => {
        return str.charCodeAt(0) <= 90
            ? str.toLowerCase()
            : str.toUpperCase()
    }).join("")
}

 

인상 깊었던 다른 사람의 풀이

function solution(my_string) {
    return my_string.split('').map(str => {
        return str === str.toUpperCase()
        	? str.toLowerCase()
        	: str.toUpperCase()
    }).join('')
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함