Skip to content

Instantly share code, notes, and snippets.

@yungyungGwon
Last active August 21, 2020 08:36
Show Gist options
  • Save yungyungGwon/a614034125206cd17e246550bd8f80e2 to your computer and use it in GitHub Desktop.
Save yungyungGwon/a614034125206cd17e246550bd8f80e2 to your computer and use it in GitHub Desktop.
Algorithm
function solution(s,n){
var answer = "";
var check = "";
for(var i = 0; i < s.length; i++){
check = s.charCodeAt(i);
if(check == 32){
answer += " ";
}
else if (check >= 65 && check <= 90){
if(check + n > 90){
answer += String.fromCharCode(check + n - 26);
}else{
answer += String.fromCharCode(check + n);
}
}
else if(check >= 97 && check <= 122){
if(check + n > 122){
answer += String.fromCharCode(check + n - 26);
}else{
answer += String.fromCharCode(check + n);
}
}
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment