I tried a really different approach, and it almost works, but I can’t work out why only half of the cipher translates; I can’t see why the rotation issue would apply here.
ie. console.log(arr); // FEEE CBDE CAMC
function rot13(str) {
var arr = str.split("");
const alphaKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
const rot13Key = "NOPQRSTUVWXYZABCDEFGHIJKLM".split("");
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < rot13Key.length; j++) {
if (arr[i] === alphaKey[j]) {
arr[i] = rot13Key[j];
}
}
}
console.log(arr.join(""));
}
rot13("SERR PBQR PNZC");