
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
function solution(s, n) {
let answer = '';
for(let i =0; i< s.length; i++){
if(s[i] === ' '){
answer += s[i]
}else{
let idx=alphabet.indexOf(s[i])
const word = idx > 25 ?
alphabet.slice(26, alphabet.length)
: alphabet.slice(0, 25 + 1)
idx = word.indexOf(s[i]) + n
if(idx >= 26){
idx -= 26
}
answer += word[idx]
}
}
return answer
}
const lower = 'abcdefghijklmnopqrstuvwxyz';
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function solution(s, n) {
const answer = s.split('')
.reduce((acc, cur)=>{
const word = lower.includes(cur) ? lower : upper
let idx = word.indexOf(cur) + n
if(idx >= 26){
idx -= 26
}
return acc + (acc === ' ' ? ' ' : word[idx])
}, '')
return answer
}