I'm studying functional programming, and I have the following problem to solve. It's an simplified version of Caesars Cipher:
- You need to write a function, which will take string encoded with Caesar cipher as a parameter and decode it.
- The one used here is ROT13 where the value of the letter is shifted by 13 places. e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
- You have to shift it back 13 positions, such that 'N' ↔ 'A'.
I made the following implementation:
const head = (str) => str; const tail = (str) => str.slice(1); const code = (str) => str.charCodeAt(0); const rot13 = (str) => str ? (code(str) < 65 || code(str) > 90) ? head(str).concat(rot13(tail(str))) : String.fromCharCode((((code(str) - 65)) + 13) % 26 + 65).concat(rot13(tail(str))) : '';
It works fine, I only want to know if there is performance issues, and what can I do to improve my code?