Solución
solution.tsTypeScript
export function rot13(text: string): string {
const MIN_VALUE = 97 // a
const MAX_VALUE = 122 // z
const ALPHABET_SIZE = MAX_VALUE - MIN_VALUE + 1 // 26
const ALPHABET_SHIFT = 13
let result = ''
for (const char of text) {
const lowerChar = char.toLowerCase()
const charCode = lowerChar.charCodeAt(0)
const inRange =
charCode >= MIN_VALUE && charCode <= MAX_VALUE
if (!inRange) {
result += char
continue
}
const isUpper = char !== lowerChar
const newChar =
((charCode - MIN_VALUE + ALPHABET_SHIFT) % ALPHABET_SIZE) + MIN_VALUE
const transformedChar = String.fromCharCode(newChar)
result += isUpper
? transformedChar.toUpperCase()
: transformedChar
}
return result
}0respuestas