retrieves all words Start with a Vowel in javaScript?
Words that Start with a Vowel
1 Answer
As it is known the Vowel a,e, i,o,u
- first, you need to lower case
- then split the string
- after that using filter
- then get the first array item
function retrieve(str) {
return str.length === 0 ? [] :
str.toLowerCase()
.replace(/[^\w\s]/g, "")
.split(" ")
.filter(a => /[aeiou]/.test(a[0]))
}
Example
retrieve('abc dsa') // ['abc']
answer Link