Solución
solution.tsTypeScript
export function rot13(text: string): string {
const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
const lowerReg = /[a-z]/
let result = ''
for (let i = 0; i < text.length; i++) {
const currentLetter = text[i]
const isLower: boolean = lowerReg.test(currentLetter)
const letterIndex = letters.indexOf(currentLetter.toLowerCase())
if (letterIndex < 0) {
result = result + text[i]
continue
}
const rot13Position = (letterIndex + 13) % 26
if (isLower)
result = result + letters[rot13Position]
else
result = result + letters[rot13Position].toUpperCase()
}
return result
}0respuestas