[프로그래머스 문제풀이50]시저 암호 자바스크립트

이ᄏᄋ·2021년 9월 29일
0
function solution(s, n) {
    var answer = '';

    for(let i=0;i<s.length;i++){
        if(s[i]===" "){
            answer+=" "
            continue; 
        }
        let charCode=s.charCodeAt(i);
        let newCharCode=charCode+n;
        if(charCode>=97&&newCharCode>122){
            newCharCode-=26;
            answer+=String.fromCharCode(newCharCode)
              console.log(charCode,newCharCode,String.fromCharCode(newCharCode));
            continue;
        }
        if(charCode<=90&&newCharCode>90){
            
            newCharCode-=26
        }
        console.log(charCode,newCharCode,String.fromCharCode(newCharCode));
        answer+=String.fromCharCode(newCharCode)
       
    }
    return answer;
}

로직 제대로 짜놓고
오타때매 왜안되지 30분고민한거 진짜 탈모유발함

profile
미쳤다.

0개의 댓글