Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created July 13, 2017 23:42
Show Gist options
  • Select an option

  • Save codenamejason/9dfa97a291aad9f1d7b5f8a642d2e833 to your computer and use it in GitHub Desktop.

Select an option

Save codenamejason/9dfa97a291aad9f1d7b5f8a642d2e833 to your computer and use it in GitHub Desktop.
Scrables a string to privatize it
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