Created
July 13, 2017 23:42
-
-
Save codenamejason/9dfa97a291aad9f1d7b5f8a642d2e833 to your computer and use it in GitHub Desktop.
Scrables a string to privatize it
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 Encode(str) { | |
| // Rreplace every letter in the string with the letter following it | |
| // by first getting the charCode number of the letter, adding 1 to it, then | |
| // converting this new charCode number to a letter using the fromCharCode function | |
| // we also check to see if the character is z and if so we simply convert the z to an a | |
| var codedString = str.replace(/[a-z]/gi, | |
| function(char) { | |
| return (char === 'z' || char === 'Z') ? 'a' : String.fromCharCode(char.charCodeAt() + 1); | |
| }); | |
| // Now successfully converted each letter to the letter following it | |
| // in the alphabet, and all we need to do now is capitalize the vowels | |
| var encodedMessage = codedString.replace(/a|e|i|o|u/gi, | |
| function(vowel) { | |
| return vowel.toUpperCase(); | |
| }); | |
| // return the final string | |
| return encodedMessage; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment