Skip to content

Instantly share code, notes, and snippets.

@kylelong
Created December 19, 2022 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylelong/b32fcbb9d0acc4c3e1751f13f2afabd3 to your computer and use it in GitHub Desktop.
Save kylelong/b32fcbb9d0acc4c3e1751f13f2afabd3 to your computer and use it in GitHub Desktop.
capitalAfterVowel.js - cassidoo 12/19/2022
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