알고리즘구현능력/문제해결능력
[javascript] 프로그래머스 / 시저 암호
dreammarker
2019. 11. 23. 13:46
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 | function solution(s, n) { var answer = ''; for(let i=0;i<s.length;i++){ let ascilCode = s[i].charCodeAt(); if(ascilCode>=65&&ascilCode<=90){ let nPlus = ascilCode+n; if(nPlus>90){ answer += String.fromCharCode(nPlus-26); } else{ answer += String.fromCharCode(nPlus); } } else if(ascilCode>=97&&ascilCode<=122){ let nPlus = ascilCode+n; if(nPlus>122){ answer += String.fromCharCode(nPlus-26); } else{ answer += String.fromCharCode(nPlus); } } else if(s[i]===" "){ answer += " "; } } return answer; } | cs |