function codeToChar( number ) {
if ( number >= 0 && number <= 25 ) // a-z
number = number + 97;
else if ( number >= 26 && number <= 51 ) // A-Z
number = number + (65-26);
else
return false; // range error
return String.fromCharCode( number );
}
输入: 0-51,否则将返回 false (范围错误) ;
或者:
var codeToChar = function() {
var abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
return function( code ) {
return abc[code];
};
})();
const A = 'A'.charCodeAt(0);
let numberToCharacter = number => String.fromCharCode(A + number);
let characterToNumber = character => character.charCodeAt(0) - A;