ASCII密码破译

描述:

根据ASCII码,将一个数字字符串转化为字母字符串。

例如:

输入cipher = “10197115121”, 返回 “easy”.

因为:

charCode(‘e’) = 101,
charCode(‘a’) = 97,
charCode(’s’) = 115
charCode(‘y’) = 121.

MyCode:

function decipher(cipher) {
  //coding and coding..
  var Str1 = "";
  var Str2 = "";

  for(let i = 0;i < cipher.length;i++)
  {
    Str1 += cipher[i];
    if(Number(Str1) >= 97 && Number(Str1) <= 122)
    {
      Str2 += String.fromCharCode(Str1);
      Str1 = "";
    }
  }
  return Str2;  
}

CodeWar:

function decipher(cipher) {
  return String.fromCharCode(...cipher.match(/1?\d\d/g))
}
function decipher(cipher) {
  return cipher.replace(/9[7-9]|1[0-1]\d|12[0-2]/g, x => String.fromCharCode(x));
}

你可能感兴趣的:(Javascript,白色七阶)