Created
December 19, 2022 09:55
-
-
Save kylelong/b32fcbb9d0acc4c3e1751f13f2afabd3 to your computer and use it in GitHub Desktop.
capitalAfterVowel.js - cassidoo 12/19/2022
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 capitalAfterVowel = (phrase) => { | |
if (phrase.length === 0) return; | |
let indices = []; | |
for (let i = 1; i < phrase.length; i++) { | |
if (/^[aeiou]$/.test(phrase[i - 1]) && !/^[aeiou]$/.test(phrase[i])) { | |
indices.push(i); | |
} | |
} | |
let copy = []; | |
phrase.split("").map((elem, index) => { | |
indices.includes(index) | |
? copy.push(elem.toLocaleUpperCase()) | |
: copy.push(elem); | |
}); | |
return copy.join(""); | |
}; | |
console.log(capitalAfterVowel("hello world")); //heLlo woRld | |
console.log(capitalAfterVowel("xaabeuekadii")); //xaaBeueKaDii |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment