Last active
May 30, 2021 14:29
-
-
Save sakilk130/74d93f8b0f76dbeba82ef83b4d7dfc68 to your computer and use it in GitHub Desktop.
FreeCodeCamp JavaScript Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rot13(str) { | |
| const Acode = 'A'.charCodeAt(); | |
| const Ncode = 'N'.charCodeAt(); | |
| const Zcode = 'Z'.charCodeAt(); | |
| return [...str] | |
| .map(function (e) { | |
| const code = e.charCodeAt(); | |
| if (Acode <= code && code <= Zcode) { | |
| if (code < Ncode) { | |
| return String.fromCharCode(code + 13); | |
| } else { | |
| return String.fromCharCode(code - 13); | |
| } | |
| } else { | |
| return e; | |
| } | |
| }) | |
| .join(''); | |
| } | |
| rot13('SERR PBQR PNZC'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment