Run details:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Chrome 53
Windows 7
Other
8 years ago
Test name Executions per second
1 38372.7 Ops/sec
2 284656.7 Ops/sec
Tests:
  • 1

    x
     
    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");
  • 2

     
    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");