
😎풀이
key를 순회
1-1. 공백일 경우 생략
1-2. 탐색 순서대로 인덱스 부여
message 순회
2-1. 공백일 경우 공백으로 치환
2-2. key에 해당하는 알파벳 순서에 맞게 치환
2-3. 복호화 문자열에 추가
- 복호화 문자열 반환
function decodeMessage(key: string, message: string): string {
const map = new Map()
for(const char of key) {
if(map.has(char)) continue
if(char === ' ') continue
map.set(char, map.size)
}
let decoded = ''
for(const char of message) {
if(char === ' ') {
decoded += ' '
continue
}
const substitution = map.get(char) ?? 0
const charCode = substitution + 97
decoded += String.fromCharCode(charCode)
}
return decoded
};