← Back to challenges

Substring Consonant-Vowel Groups

JavaScriptHardstringsloops

Instructions

Write two functions:

  1. One to retrieve all unique substrings that start and end with a vowel.
  2. One to retrieve all unique substrings that start and end with a consonant.

The resulting array should be sorted in lexicographic ascending order (same order as a dictionary).

Examples

getVowelSubstrings("apple")
➞ ["a", "apple", "e"]

getVowelSubstrings("hmm") ➞ []

getConsonantSubstrings("aviation")
➞ ["n", "t", "tion", "v", "viat", "viation"]

getConsonantSubstrings("motor")
➞ ["m", "mot", "motor", "r", "t", "tor"]

Notes

  • Remember the output array should have unique values.
  • The word itself counts as a potential substring.
  • Exclude the empty string when outputting the array.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.