题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
let str = readline(); let strArr = [...str]; let res = []; for(let v of strArr) { //如果是大写字母 if(/[A-Z]/.test(v)){ if(v.toLowerCase() === 'z'){ v = 'a'; }else{ v = v.toLowerCase().charCodeAt(0)+1*1; v = String.fromCharCode(v); } res.push(v); }else if(/[a-z]/.test(v)){//如果是小写字母 if('abc'.split('').includes(v)){ v = 2; }else if('def'.split('').includes(v)){ v = 3; }else if('ghi'.split('').includes(v)){ v = 4; }else if('jkl'.split('').includes(v)){ v = 5; }else if('mno'.split('').includes(v)){ v = 6; }else if('pqrs'.split('').includes(v)){ v = 7; }else if('tuv'.split('').includes(v)){ v = 8; }else if('wxyz'.split('').includes(v)){ v = 9; } res.push(v); }else{ res.push(v); } } console.log(res.join(''))