mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +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) => {
|
return str.replace(/[a-z]/gi, (char) => {
|
||||||
|
const charCode = char.charCodeAt()
|
||||||
|
|
||||||
if (/[A-Z]/.test(char)) {
|
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