| Viewed 63 times

retrieves all words Start with a Vowel in javaScript?


Words that Start with a Vowel

1 Answer
Mohammad Qandeel
Answered
9

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']



Related Questions