Write a function that takes in a string and for each character, returns the distance to the nearest vowel in the string. If the character is a vowel itself, return 0.
Vowels are : aeiouAEIOU
For the purposes of this challenge, y
is not a vowel.
The input will be a string consisting of uppercase and lowercase letters.
Edge cases :
You will be tested for empty strings as well, so
''
is a valid input, which should return[]
The input string will contain at least one vowel (unless it is the empty string)
Obviously in case someone missed it uppercase and lowercase letters both exist
It is also possible you end up getting nothing but vowels in a string, the answer in that case obviously would be 0 across the board
Examples :
distanceToNearestVowel("aaaaa") ➞ [0, 0, 0, 0, 0]
distanceToNearestVowel("abcdabcd") ➞ [0, 1, 2, 1, 0, 1, 2, 3]
distanceToNearestVowel("shopper") ➞ [2, 1, 0, 1, 1, 0, 1]
distanceToNearestVowel("") ➞ []
distanceToNearestVowel("AaAaEeIeOeAU") ➞ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
distanceToNearestVowel("bcdfghjklmno") ➞ [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] ----> added thnx to @Shaggy
Input : String
Output : Array or string (or equivalent in your language of choice)
This is code-golf, so the shortest answer in each language wins.
I will probably not mark any answer as accepted (since different languages different standards)
If you can and have some time kindly do explain your answers (this is mostly for me so I can understand how they work; I like learning. Obviously not compulsory.)