Distance to nearest vowel
Write a function that takes a string as argument. Each character in the string will be a letter. The function should return a sequence containing the distances from each corresponding letter in the string to the nearest vowel in the string.
For example:
(nearest-vowels "aeiou") ;=> [0 0 0 0 0] ;; if the letter is a vowel, the distance is 0
(nearest-vowels "babbb") ;=> [1 0 1 2 3]
(nearest-vowels "babbba") ;=> [1 0 1 2 1 0]
Notes:
- All input strings will contain at least one vowel and all letters.
- Vowels are a, e, i, o, and u.
Thanks to this site for the challenge idea where it is considered Expert level in JavaScript.
g7s, Your solution looks interesting, but it fails on "the", should be (2 1 0), but yields (1 1 0), or "bbbba" should be (4 3 2 1 0) instead of (1 2 2 1 0) - it's a nice idea, going back halfway to the previous vowel occurrence, maybe a small tweak is needed to make it work...