Test name | Executions per second |
---|---|
1 | 38372.7 Ops/sec |
2 | 284656.7 Ops/sec |
function rot13(str) { // LBH QVQ VG!
var decode = [];
var decodeString = "";
for (i = 0; i < str.length; i++) {
decode.push(str.charCodeAt(i));
if (decode[i] >= 78 && decode[i] <= 90) {
decode[i] = decode[i] - 13;
} else if (decode[i] >= 65 && decode[i] < 78) {
decode[i] = decode[i] + 13;
}
decodeString += String.fromCharCode(decode[i]);
}
return decodeString;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
function rot13(str) { // LBH QVQ VG!
return str.replace(/[A-Z]/g, (L) => String.fromCharCode(65 + (L.charCodeAt(0) - 65 + 13) % 26));
}
rot13("SERR PBQR PNZC");