What if you change the parameters inside the function, and then use return to return the parameters, but display the original input parameters?

clipboard.png
just a few weeks after contact with javascript, I encountered a question about Caesar"s password, so I started to write it, but I haven"t finished it yet. It is found that although the parameters have been changed inside the function, what should I do if I want to return the parameters that have been changed (to achieve the effect of letter shift), but return the original parameters as they are?

Mar.16,2021

str = str.replace...

as a matter of fact, there is no need to move back and forth between charCodeAt/fromCharCode. It can be handled completely and transferred to Unification

.
function rot13(str){
    //    Unicode
    var empty = Array.prototype.map.call(str,function(s){return s.charCodeAt(0)})
    // 
    .map(function(num){
        // left
        if(num >=65 && num <= 77){
            return num + 13;
        // right
        } else if(num >= 78 && num <= 90){
            return num;
        // 
        } else {
            return num;
        }
    });
    //  Unicode 
    return String.fromCharCode.apply(null, empty);
}
After

str performs replace, you need to assign the obtained content back to str


    In line 9 of
  1. code, do not use in , in to determine whether an object has an attribute, and not to judge whether an array contains an element. Use includes instead;
  2. Line 10 of
  3. code uses str = str.replace to reassign str ;
function rot13 (str) {
  var empty = [];
  for (var i = 0; i < str.length; iPP) {
    empty.push(str.charCodeAt(i))
  }
  var left = empty.filter(function (x) {return x >= 65 && x <= 77})
  var right = empty.filter(function (y) {return y >= 78 && y <= 90})
  for (var j = 0; j < str.length; jPP) {
    if (left.includes(str.charCodeAt(j))) { // includes
      str = str.replace(str[j], String.fromCharCode(str.charCodeAt(j) + 13)) // 
    }
  }
  return str
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c4f3-2bb57.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c4f3-2bb57.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?