Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created September 25, 2021 21:46
Show Gist options
  • Save crutchcorn/c22b6085efb8632efbd1a5b8b5a8b5ec to your computer and use it in GitHub Desktop.
Save crutchcorn/c22b6085efb8632efbd1a5b8b5a8b5ec to your computer and use it in GitHub Desktop.
const t = readline();
keyCodeMap = {}
addRangeToKeyCodeMap = (start, len) => {
for (i = 0; i < len; i++) {
keyCodeMap[start + i] = start + len - 1 - i
}
}
addLatinToKeyCodeMap = start => addRangeToKeyCodeMap(start, 26)
// Uppercase
// 65 = A 90 = Z
addLatinToKeyCodeMap(65)
// Lowercase
// 97 = a 122 = z
addLatinToKeyCodeMap(97)
// Numbers
// 48 = 0, 57 = 9
addRangeToKeyCodeMap(48, 10)
// [ = 91
// ] = 93
// } = 125
// { = 123
// ( = 40
// ) = 41
keyCodeMap[91] = 93
keyCodeMap[93] = 91
keyCodeMap[125] = 123
keyCodeMap[123] = 125
keyCodeMap[40] = 41
keyCodeMap[41] = 40
console.log([...t].map(l=>{
mapKey = keyCodeMap[l.charCodeAt(0)]
if (!mapKey) return l;
return String.fromCharCode(mapKey)
}).join(''))
// Write an answer using console.log()
// To debug: console.error('Debug messages...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment