Created
January 23, 2019 03:06
-
-
Save hhenrichsen/2b939cb42e53a80e988281a4f257e09c to your computer and use it in GitHub Desktop.
This file contains 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 outerOffset = 65; //ASCII code of first letter | |
const innerOffset = outerOffset - 13; //Number that is subtracted to determine new ASCII code | |
const allowedChars = /[A-Z]/; //Characters to be transformed | |
var rot13 = (str) => str.toUpperCase() //Function declaration, accept lowercase | |
.split("") //Basic stream transforms | |
.map(c => (c.match(allowedChars) ? //Check if its a character to be transformed; | |
String.fromCharCode(outerOffset + ((c.charCodeAt(0) - innerOffset) % 26)) //Transform it | |
: c)) //Don't transform it | |
.join(""); //Join it back into a string. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment