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.
@mike-thompson-8day Nice solution - but you can make it even shorter as you don't need at-start? and can use 'pyramid everytime to add to the result, as backwards and forwards are always present even when the first vowel is encountered? I removed the extra code and all tests still pass.