题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
//利用Map可以使用任意类型作为键的特性
let pwd = readline()
let newPwd = ''const dict = new Map([
[/[a-c]/g, '2'],
[/[d-f]/g, '3'],
[/[g-i]/g, '4'],
[/[j-l]/g, '5'],
[/[m-o]/g, '6'],
[/[p-s]/g, '7'],
[/[t-v]/g, '8'],
[/[w-z]/g, '9'],
[/[A-Y]/g, char => String.fromCharCode(char.toLowerCase().charCodeAt() + 1)],
[/Z/g, 'a']
])
let iter = dict.keys()
for (key of iter) {
newPwd = pwd.replace(key, dict.get(key))
pwd = newPwd
}
console.log(newPwd)