Skip to content

Instantly share code, notes, and snippets.

@brianmarete
Created February 28, 2017 18:22
Show Gist options
  • Save brianmarete/658873db6762cac3cf02db998db3240b to your computer and use it in GitHub Desktop.
Save brianmarete/658873db6762cac3cf02db998db3240b to your computer and use it in GitHub Desktop.
JavaScript function that removes all the vowels in a string
function removeVowels(sentence) {
var vowels = ['a', 'e', 'i', 'o', 'u'];
var newSentence = [];
for (var i = 0; i < sentence.length; i++) {
if (vowels.includes(sentence[i])) {
newSentence.push('-');
} else {
newSentence.push(sentence[i]);
}
}
// This would also work but it uses RegEx
// return sentence.replace(/[aeiou]/ig, "");
return newSentence.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment