It's a Caesar cipher program, I have written this code by myself and want to convert this for loop into .map JavaScript built-in function, I have tried so many times but can't figure out.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map
There are many questions on .map on this website but that doesn't work for me.
function rot13(str) {
var chArray = [];
str = str.split("");
for(var i in str){
var char = str[i].charCodeAt(0);
if(/[A-M]/g.test(str[i])){
chArray.push(char + 13);
}
else if(/[N-Z]/g.test(str[i])){
chArray.push(char - 13);
}
else chArray.push(char);
}
str = String.fromCharCode.apply(String,chArray);
return str;
}
rot13("SERR PBQR PNZC");