function solution(s, n) {
let upper = [];
let lower = [];
let answer = '';
for (let i = 'A'.charCodeAt(); i<='Z'.charCodeAt(); i++) {
upper.push(String.fromCharCode(i));
}
for (let i = 'a'.charCodeAt(); i<='z'.charCodeAt(); i++) {
lower.push(String.fromCharCode(i));
}
for (let i = 0; i< s.length; i++) {
if(s[i] === ' ') {
answer += s[i];
continue
}
if(upper.includes(s[i])) {
let Index = upper.indexOf(s[i]);
answer += upper[(Index + n) % 26];
continue;
}
let Index = lower.indexOf(s[i]);
answer += lower[(Index + n) % 26];
}
return answer;
}
참고
https://velog.io/@michael00987/javascript%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EC%8B%9C%EC%A0%80-%EC%95%94%ED%98%B8