Created
February 28, 2017 18:22
-
-
Save brianmarete/658873db6762cac3cf02db998db3240b to your computer and use it in GitHub Desktop.
JavaScript function that removes all the vowels in a string
This file contains 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
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