I have the logic down and all the characters are translating nicely I am just struggling to figure out how to keep the punctuation of the original string in my new one. I’m sure this has something to do with the way I set up this problem to push into an array.
Any help would be greatly appreciated!
function rot13(str) {
const abc = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz".toUpperCase();
let arr = [];
for(let i = 0; i < str.length; i++){
let char = str[i];
if(abc.includes(char,0)){
let index = abc.indexOf(char,0) + 13;
arr.push(abc[index]);
}
}
let replace = arr.join('');
console.log(replace);
}
rot13("SERR CVMMN!");
Challenge: Caesars Cipher
Link to the challenge: