merge: cache repeated function calls (#962)

This commit is contained in:
Fahim Faisaal
2022-03-28 22:49:29 +06:00
committed by GitHub
parent 27ae62e5c9
commit 7d57f7f1a7

View File

@ -11,11 +11,13 @@ const Atbash = (str) => {
}
return str.replace(/[a-z]/gi, (char) => {
const charCode = char.charCodeAt()
if (/[A-Z]/.test(char)) {
return String.fromCharCode(90 + 65 - char.charCodeAt())
return String.fromCharCode(90 + 65 - charCode)
}
return String.fromCharCode(122 + 97 - char.charCodeAt())
return String.fromCharCode(122 + 97 - charCode)
})
}