Created
March 15, 2023 13:25
-
-
Save LucianBuzzo/44192bcad8702d3a760b61483976d020 to your computer and use it in GitHub Desktop.
Recursive Caesar Cipher
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
| const recursiveCaesarCipher = (shift, text) => { | |
| const inner = (shift, [ letter, ...rest]) => { | |
| const index = alphabet.indexOf(letter); | |
| const newIndex = (index + shift) % alphabet.length; | |
| return [ | |
| index >= 0 ? alphabet[newIndex] : letter, | |
| ...rest.length ? inner(shift, rest) : [] | |
| ] | |
| } | |
| return inner(shift, [ ...text ]).join(''); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment