/*
* @lc app=leetcode.cn id=2325 lang=typescript
*
* [2325] 解密消息
*/
// @lc code=start
function decodeMessage(key: string, message: string): string {}
// @lc code=end
function decodeMessage(key: string, message: string): string {
let chs = [...new Set(key)].filter(ch => ch !== ' '),
map = new Map<string, string>()
for (let [i, ch] of chs.entries()) {
map.set(ch, String.fromCharCode(i + 97))
}
let res = ''
for (let ch of message) {
res += map.get(ch) ?? ' '
}
return res
}
test.each([
{
input: { key: 'the quick brown fox jumps over the lazy dog', message: 'vkbs bs t suepuv' },
output: 'this is a secret',
},
{
input: { key: 'eljuxhpwnyrdgtqkviszcfmabo', message: 'zwx hnfx lqantp mnoeius ycgk vcnjrdb' },
output: 'the five boxing wizards jump quickly',
},
])('input: key = $input.key, message = $input.message', ({ input: { key, message }, output }) => {
expect(decodeMessage(key, message)).toEqual(output)
})