michaelp0730
11/5/2019 - 4:05 AM

Letter Changes

For each letter in a string, replace it with the next letter in the alphabet. If the current character is z, return A. Also, all vowels should be capitalized.

function letterChanges(str) {
    let newStr = str.toLowerCase().replace(/[a-z]/gi, function(char) {
        if (char === 'z' || char === 'Z') {
            return 'a';
        } else {
            return String.fromCharCode(char.charCodeAt() + 1);
        }
    });
    
    newStr = newStr.replace(/a|e|i|o|u/gi, function(vowel) {
       return vowel.toUpperCase(); 
    });
    
    return newStr;
}