mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
merge: cache repeated function calls (#962)
This commit is contained in:
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user