Here is the problem, Caesars Cipher.
Here is my code:
function rot13(str) {
function isLetter(str) {
return str.match(/[A-Z]/);
}
let result = [];
let garbage = {};
let en = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
let de = ['N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M'];
for(let i=0; i<str.length; i++){
for(let j=0; j<en.length; j++){
if(str[i] === en[j]){
result.push(de[j]);
}
}
}
for(let i=0; i<str.length; i++){
if(!isLetter(str[i])){
garbage[i] = str[i];
}
}
let gKeys = Object.keys(garbage);
for(let i =0; i<gKeys.length; i++){
result.splice(parseInt(gKeys[i]),0,garbage[gKeys[i]])
}
return result.join("");
}
Do have a better idea, please let me know?