[Question]
  [
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](/questions/tagged/code-golf "show questions tagged '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.)
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
e€ØcTạⱮJṂ€
```
A monadic Link that accepts a list of characters and yields a list of non-negative integers.
**[Try it online!](https://tio.run/##y0rNyan8/z/1UdOawzOSQx7uWvho4zqvhzubgAL///9XKs7ILyhILVICAA "Jelly – Try It Online")**
### How?
```
e€ØcTạⱮJṂ€ - Link: list of characters, S  e.g. "shopper"
  Øc       - vowels                            "aeiouAEIOU"
 €         - for each (c in S):
e          -   (c) exists in (vowels)?         [0,0,1,0,0,1,0]
    T      - truthy indices                    [3,6]
       J   - range of length (S)               [1,2,3,4,5,6,7]
      Ɱ    - map with:
     ạ     -   absolute differences            [[2,5],[1,4],[0,3],[1,2],[2,1],[3,0],[4,1]]
        Ṃ€ - minimum of each                   [2,1,0,1,1,0,1]
```
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 23 bytes [SBCS](https://github.com/abrudz/SBCS)
```
⌊/∘|⍳∘⍴∘.-∘⍸'aeiou'∊⍨⎕C
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=e9TTpf@oY0bNo97NQOpR7xYgqacLZu5QT0zNzC9Vf9TR9ah3xaO@qc4A&f=Szu0QkE9EQTUgXRScgoIA5nFGfkFBalFQBYQOSY6Jrqmeqb6pzqGArlAFWnpGVnZObl5@eoA&i=AwA&r=tryapl&l=apl-dyalog&m=train&n=f)
Needs version 18 for the new Case Convert system function.
`⎕C` convert the argument to lower. According to the documentation this *folds* the case for case-less comparisons but it is actually implemented as converting to lower case, at least for the latin alphabet.  
`'aeiou'∊` for each character, is it a vowel?  
`⍸` get all indices of 1's (vowels)
`⍳∘⍴` all indices from 1 to the length of the string  
`∘.-` table of differences between each index and each index of a vowel  
`|` the absolute value of each difference  
`⌊/` for each index in the string, get the minimum value
[Answer]
# [Haskell](https://www.haskell.org/), 70 bytes
```
(\z->[minimum[abs$i-j|(j,c)<-z,elem c"aeiouAEIOU"]|(i,_)<-z]).zip[0..]
```
[Try it online!](https://tio.run/##FckxDsIgFADQq/yQDjQB4gGsiYODk5MTJQYJ2F@B/hS7kJ5djG99ky1vH2MLw9j4WOVJJ8yYtqTts3Qo553PwvVHWYWPPoFj1uOynS/X252ZnaN4/NP0qiLpg1KmJYsZBqAV8wc6CMDKtBD5lbWvC9G@SpOO6Ac "Haskell – Try It Online")
[Answer]
# JavaScript (ES6), ~~83~~ 69 bytes
Expects an array of ASCII codes.
```
a=>a.map((_,x)=>a.map(m=c=>m=(v=x--<0?~x:-~x)>m|~2130466>>c&1?m:v)|m)
```
[Try it online!](https://tio.run/##bZFRT4MwEMff@RQXHkxJSgfbRJ22CzF78MknnwgxtSvDSSmBhfCw8NWRVsZM9HJtrr1f7/5tj7zljag/q5Nf6r0cMjpwyjhRvELoHXfeZaGooExR1NLO95@Cbd9t/L7zmDr3y3AVrKOIMXETbtWm9c7KGx4TB8DlxlwMky0WkAQYrp5a6EPszZi4CQoxLO08xytLN7muKllfihr6NzcFFr02nlG7H/OY7@SLfJXx28j8UfWv25OjyuyQH78KVWr3p2Jomo7AA4Z7DHcYIgy3GNaj3vkGqZM6JNP1joscNUAZCF02upCk0AeUoYQQ0qT2nYXNEpHz@nn8kPiEPGPDNw "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>                      // a[] = input array
a.map((_, x) =>           // for each entry at position x in a[]:
  a.map(m =               //   initialize m to a non-numeric value
    c =>                  //   for each ASCII code c in a[]:
    m =                   //     update m:
      ( v =               //       set v to abs(x)
        x-- < 0 ? ~x      //       and decrement x afterwards
                : -~x     //
      ) > m |             //       if v is greater than m
      ~2130466 >> c & 1 ? //       or c is the code of a consonant:
        m                 //         leave m unchanged
      :                   //       else:
        v                 //         update it to v
  ) | m                   //   end of inner map(); yield m
)                         // end of outer map()
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~88~~ 85 bytes
-3 bytes thanks to [dingledooper](https://codegolf.stackexchange.com/users/88546/dingledooper)
```
lambda s,E=enumerate:[min(abs(j-i)for j,y in E(s)if y in'aeiouAEIOU')for i,_ in E(s)]
```
[Try it online!](https://tio.run/##NYo9C4MwFEX3/oq3JYId2lFwyODg1MmpLeVZX5pnzQcaKf76NBZ6uRfOhRO2aLw7J13f0oS2HxCWsqnJrZZmjFRdLTuJ/SLHIxfazzCWG7CDRi4Fa9hZILFfVdNeOvFTuHz8lXv6GJ4IThWEmV0ELdmFNcqiSAL3iIPA/jnsy7gYHwLNmXIVKmyopQupLt9s6JcZ35N1XnwB "Python 2 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 72 bytes, \$O(n^2)\$
```
f x|q<-zip[0..]x=[minimum[abs$i-j|(j,v)<-q,elem v"aeiouAEIOU"]|(i,_)<-q]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hoqbQRrcqsyDaQE8vtsI2OjczLzO3NDc6MalYJVM3q0YjS6dM00a3UCc1JzVXoUwpMTUzv9TR1dM/VCm2RiNTJx4kGfs/NzEzz7agKDOvRCVNyQkIHIE4EcRwUvoPAA "Haskell – Try It Online")
I realized I I was still holding onto an efficiency mindset when I was golfing this earlier, which isn't needed for codegolf. This goes through every letter in the input and checks the distance to every vowel taking the minimum.
# [Haskell](https://www.haskell.org/), ~~95~~, 92 bytes, \$O(n)\$
```
a%b=sum[b+1|all(/=a)"aeiouAEIOU"]
g u=u(%)=<<length
zipWith min.g scanr<*>tail.g(scanl.flip)
```
[Try it online!](https://tio.run/##FYexCsIwFAD3fkUIFlKFiHsitODg5CQO4vAqSfroSwxNsoj/HtuDg7sJ0myIaoV21Kn453g4/YBIHDV0HAx@Sn@53u781ThWdBFtp5UiE1yeGqu/GB@YJ@YxSMfSG8Ki9ucMSNKJbUlawthVDxh0XDDkneXDSr8KWwy8/gE "Haskell – Try It Online")
We create a scanning function `(%)`. This takes a number and a character. If the character is a vowel it gives `0` otherwise it gives one more than the provided number.
We scan the input from right to left starting with the total length of the list
```
 bbabbabb
789012012
```
We chop off the extra number at the start. Then we do the same scan in the other direction
```
bbabbabb
210210987
```
We don't bother chopping the extra here, because next we zip the two together taking the minimum entry in each list
```
bbabbabb
21011012
```
And that is our result.
This answer happens to implement the original spec of the challenge giving the length of the list when there are no vowels, whereas the first has an error on this case.
[Answer]
# [R](https://www.r-project.org/), 82 bytes
*-1 byte thanks to [@Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen).*
```
function(x)Map(function(i)min(abs(i-el(gregexpr("[aeiou]",x,T)))),seq(l=nchar(x)))
```
[Try it online!](https://tio.run/##hZC/TsMwEMb3PoUVlrN0lSj/O3TIwMAALIWlynBNr4nBtYOdiDxNH44XCQ5USZGK/OnOuhu@38mf6zbK12RyXtonJse@frWfrBfdtjF5rayBVj5SBcOq5E4ZoLUHNWUNheOC28pBsiJWtskSbHEpg9DzB@iFyUtyASJl1xgdjsHpi5BQr0RKcfa134vVOYqxsskk5l7nm77/AGYoLn7eYb6Mk3xpq4rdCDpGHIY4pbcf9EuJW1JK6Z4f@JnTl39yOFlxcshlW5Rv73pn7Eie9f8JgDmKOxS3KG5QXKO4CikNuWXdNw "R – Try It Online")
(or **[R](https://www.r-project.org/)>=4.1, 68 bytes** replacing both `function` appearances with `\`)
---
Previous solution (with explanation):
### [R](https://www.r-project.org/), 83 bytes
```
function(x)apply(abs(outer(seq(l=nchar(x)),el(gregexpr("[aeiou]",x,T)),`-`)),1,min)
```
[Try it online!](https://tio.run/##fY@xDoJADIZ3noLgcpeciejMwODgogu6EBIKVCHBu/MOIr4MD@eLIChBBuBP2zT5@7WpapJMF8Bj9MQRQaEuLuKJudNcSx4XmeCkoiBl/iIQaSLKAhXR@CC5w@MUVOtShjm5KbxhJRWxfMBMlIHFKua1XrgO22qze8bpzC1iQSeLmqt3XZv@hpn/CAxjloripMsxaDNz@61Dv1vYoFMhJaphwRjtmwW6xXr96IVRF1zY4wFP6J6n/5yMwGg@ "R – Try It Online")
```
function(x){      # a function taking string x
a=seq(l=nchar(x)) # make a sequence 1..length(x) (empty if x empty)
b=el(             # take first (and only) element of list with
     gregexpr(    # positions
      "[aeiou]",  # of vowels
      x,          # in x
      T))         # with ignored case
c=outer(a,b,`-`)  # matrix of position differences 
                  # with length(x) rows and (# vowels in x) columns
d=abs(c)          # absolute value
apply(d,1,min)    # row-wise minimum
}
```
[Answer]
# [jq](https://stedolan.github.io/jq/), ~~73~~ ~~69~~ 62 bytes
-7 bytes thanks to [Michael Chatiskatzi](https://codegolf.stackexchange.com/users/90812/michael-chatiskatzi)!
```
[explode[]%32]|keys[]as$y|[indices(1,5,9,15,21)[]-$y|fabs]|min
```
[Try it jqplay!](https://jqplay.org/s/t4DNHUMWLd) `fabs`, like many of the math builtins, doesn't seem to work on TIO.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0, 12 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
¬£ð\v maY rm
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&flags=LVE&code=rKPwXHYgbWFZIHJt&input=ImJjZGZnaGprbG1ubyI) or [run all test cases](https://petershaggynoble.github.io/Japt-Interpreter/?v=2.0a0&code=rKPwXHYgbWFZIHJt&input=WwoiYWFhYWEiCiJhYmNkYWJjZCIKInNob3BwZXIiCiIiCiJBYUFhRWVJZU9lQVUiCiJiY2RmZ2hqa2xtbm8iCl0tbVI)
```
¬£ð\v maY rmUl     :Implicit input of string U
¬                  :Split
 £                 :Map 0-based indices Y
  ð                :  0-based indices in U of
   \v              :    RegEx /aeiou/i
      m            :  Map
       aY          :    Absolute different with Y
          r        :  Reduce by
           m       :    Minimum
```
[Answer]
# [J](http://jsoftware.com/), 36 34 bytes
```
i.@#<./@(|@-/~I.)'aeiou'e.~tolower
```
[Try it online!](https://tio.run/##XY5tC4JADMff9ylGvTiF88yekwIlCoQgCPoAl52pWSdW9Cb86tddimdtbIztt@2fii5BESxdQIChD64Mi8Bqv92IhHi9BbE94@1ZdhkQE1GW8CdipHzwjL9YIcwOC2MORgSIKkMmWOpE7a3pMTypqAEMDobBNzf1UNP3mOc5Kyq4jdWFJisEId3xqU/XLGA75h/@5Py6XpG6onOcXrLrjVcrjvolP80xzDBMMUwwjDGMpMpGt/gA "J – Try It Online")
*-2 thanks to FrownyFrog*
Solved independently, but appears to be almost identical to ovs's APL approach.
[Answer]
# JavaScript, 75 bytes
```
a=>(g=a=>a.map(n=>p=/[aoeui]$/i.test(n)?0:++p>n?n:p,p=1/0).reverse())(g(a))
```
[Try it online!](https://tio.run/##bZBNb4MwDIbv@xVWtUOiZgnse5VCxWGHnXbaCXHwqKF0NIkI699nUKG00mLZlg9@bL8@4Al91bduuDN2R2OtR9QZa/SUUR7RMaMzp1WBln7b8la1ciA/MMO3yWa9dpnZmo0TTqcq4bKnE/WeGOesYcj5WFnjbUeysw2rWSGlXOFsq5JzWEwpKBIBFy9vYth3tZsjkAuWCrg/51A/RHm/t85Rf1k889fkUkTh63MDHO3MMcd3@qBPyr/O1D91UY/OmtTWzf7w0x2NDbPS@dQJeRPwKuBFwLOAJwGPk@7wiXL8Aw "JavaScript (Node.js) – Try It Online")
Input an array of characters, output an array of numbers. For input which is both non-empty and contains no vowels, it returns `Infinity`.
It would be 74 bytes if we allow return `false` in place of 0:
```
a=>(g=a=>a.map(n=>p=++p>n?n:/[^aoeui]/i.test(n)&&p,p=1/0).reverse())(g(a))
```
A typical solution runs in \$O\left(n\right)\$. Looks like most other answers are \$O\left(n^2\right)\$.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 72 bytes
```
lMin@Abs@Pick[j-#,Capitalize@l,"A"|"E"|"I"|"O"|"U"]&/@(i=0;j=i++&/@l)
```
[Try it online!](https://tio.run/##FcpLCsIwFIXhuctIoSi26FwqCaLQgbRQHZUOrjFt0@ZR0jjxtQh34ApdQk0ufPAfuBJsyyRYTmGqk0n8Pt8jV5hcRpxz2pddHEQ7GLgFwe8MiwgR9ER7J3Uy54yqcIXnPFlvuoQvl26IxZQbrmx50oV10ZRBlKrhZg/ayCre1njXggFqmRlxUIXvgoJ6P2YI/KHIxYVePd9jq4eBGZ8eAQJ7lrKMkbPf7qtu2q4XUmk0e01/ "Wolfram Language (Mathematica) – Try It Online")
Input a character list.
[Answer]
# JavaScript, 73 bytes
Takes input as an array of characters.
```
a=>a.map((b,x)=>a.map(c=>b=!/[aeiou]/i.test(c,y=x--<0?~x:-~x)|y>b?b:y)|b)
```
[Try it online!](https://tio.run/##NY6xCoMwGIT3vkWdEjCxs20iDh06deokDn9itFo1wdgSQXz11BR6cPB9cMN18AErp9bMZNSV8jXzwDjQAQxCInb4L5JxwY5JAarV7zJp6azsjGS8MEfI5ZRtLiWbw@vCRSbSBa8C@3NxiCAkincQsgoNbJ/aGDUFDM0hh6u6qbvKH8H3Vd08u1c/jHr38nfAMS71aHWvaK8bVKOCUupKjLH/Ag)
This started off at around 100 bytes but I tapped away at it through most of an insomniac night, determined to beat Arnauld's 83 only to come back this morning to discover that not only had he blown me out of the water by knocking 14 bytes off his score but tsh had also sniped me by a byte. Borrowing Arnauld's absolute value trick, though, allowed me to save 3 bytes putting me in second place (for now) so I'll take it. Still think there's a byte or 2 more to be shaved off this but that'll need to wait until caffeine kicks in.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 63 bytes
```
iL$`(?=(.*?)[aeiou])?.(?<=[aeiou](.*?))?
$.1;$.2
%(N`\d+
0L`\d+
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8D/TRyVBw95WQ0/LXjM6MTUzvzRW015Pw97GFsoDy2jac6noGVqr6BlxqWr4JcSkaHMZ@ICo//8TQYCLKzEpOQWEubiKM/ILClKLuIDAMdEx0TXVM9U/1TGUiwsom5aekZWdk5uXDwA "Retina – Try It Online") Link includes test cases. Explanation:
```
iL$`(?=(.*?)[aeiou])?.(?<=[aeiou](.*?))?
$.1;$.2
```
Looping over each letter, look for nearby vowels.
```
%(
```
Loop over each result separately.
```
N`\d+
0L`\d+
```
Take the minimum. (I feel there should be a shorter way to do this, but I can't think what is might be.)
[Answer]
# [PHP](https://php.net/) < 7.1.0 -F , 125 bytes
```
for(;$c=($a=$argn)[$i++];$r[]=$p)for($j=0,$p=-1;$p<0;$j=$j<0?-$j:-$j-1)!stripos(_aeiou,$a[$i+$j-1])?:$p=abs($j);var_dump($r);
```
[Try it online! (wrong PHP version, works with some test cases)](https://tio.run/##1UxLCoMwFLxKC7NI0EDcGoO7XkJEntpPhJpHoj1@0@QYHZiBYT784tT1nPXhgzBYrABZUHjucoCrqtEgDKMFy1LAZnUNtqox4E6b7LF1ulfY2kzVyGs8gmMfxUR3588aVG5KNMq@zVOaY76R5kNhWs83CwRp0uV/kGhe1sKv58P5PSZ1@wE "PHP – Try It Online")
[test the last case (or others) with the right version of PHP](http://sandbox.onlinephpfunctions.com/code/95fb8ff55bd8c4cb1a6bfee9bdcf3a3cee631372)
This is the first shot I gave it to it, without looking at other answers, pretty sure it can be golfed more using subte tricks.
Straightforward code, only for PHP < 7.1.0 because for newer versions, negative index is supported and accesses chars from the end of the string
displays NULL or empty string for an empty input, depending on the site. It would cost 5 bytes for initialization of `$r` to an empty array to be sure to have an array as output.
[Answer]
# JavaScript, ~~95~~ 85 bytes
```
a=>[...a].map((_,B,V)=>Math.min(...V.map((c,C)=>/[aeiou]/i.test(c)?C>B?C-B:B-C:1/0)))
```
## Edits :
@Neil Thanks for the 10 bytes
* since I've already spread the array, I can just call it using map's third param instead of spreading again
* Instead of `Math.abx()` do `C>B?C-B:B-C`
* change length a.length to 1/0
Any suggestion on how to improve would be appreciated
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 7 bytes
```
ẏƛ?ATεg
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=1#WyJBIiwiIiwi4bqPxps/QVTOtWciLCIiLCJhYWFhYWFcbmFiY2RhYmNkXG5zaG9wcGVyXG5cIlwiXG5BYUFhRWVJZU9lQVVcbmJjZGZnaGprbG1ubyJd)
-4 bytes thanks to Lyxal.
```
 ƛ      # For each
ẏ       # number from 0 to len(input)
    T   # Indices of
   A    # vowels
  ?     # In the input
     ε  # Difference between each index and the given number
      g # Find the minimum
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 20 bytes
```
ＩＥθ⌊↔⁻κΦＬθ№aeiou↧§θλ
```
[Try it online!](https://tio.run/##PYxBCoMwEAC/EjytkL6gJxGEgkK/sKZLE4zZmGza/n5rL53jwIzzWBxjVL2XkARGrAILZjisWUIKe9thWCvHJgSnaBU2a6YQhQrMlJ7i4eitGbmddYcUuHXWzPym4rASDHJLD/r8frH/c1WtnnOmopdX/AI "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  θ                     Input string
 Ｅ                      Map over characters
         θ              Input string
        Ｌ               Length
       Φ                Filter over implicit range
                 §θλ    Inner character
                ↧       Lowercase
          №             Is contained in
           aeiou        Lowercase vowels
     ⁻                  Vectorised subtract
      κ                 Current index
    ↔                   Vectorised absolute value
   ⌊                    Minimum
Ｉ                       Cast to string
                        Implicitly print
```
[Answer]
# [Python 2](https://docs.python.org/2/), 112 bytes
```
s=input();n=0;exec"print min(abs(y-n)for x in'aeiouAEIOU'if x in s for y,z in enumerate(s)if z==x);n+=1;"*len(s)
```
[Try it online!](https://tio.run/##HYy9DsIgFIVfhbAU1CbqShgcOjg5@QC03sab2AvhJ4G@PAWHM5zvOzmuxK@le61BI7kUhVSkrwoyLNx5pMg2JGHmIMpIcrWeZYY0GECbHtPz9R5w/SMWWLflsvcClDbwJoIIsg12rXM7Puub4qcfUKO1cjMvnx5@AA "Python 2 – Try It Online")
# [Python 2](https://docs.python.org/2/), 115 bytes
```
def f(s,n=0):print min(abs(y-n)for x in"aeiouAEIOU"if x in s for y,z in enumerate(s)if z==x);n+1<len(s)and f(s,n+1)
```
[Try it online!](https://tio.run/##JY2xDsIgFEV/5YWJl9bEOqoMDh2cOvUDqDwiiX00QJPSn8eiwx3uOTe5S05vz5dSDFmwMrasznhdguMEs2OppyjzidH6ABs4FpqcXx/9cxiFsz8EEarN7V4L8TpT0IlkxGOwK7XhjZvu/iE@kGbzv2k6LFYKPb1MjcDyBQ "Python 2 – Try It Online")
# Ungolfed
```
# Relavant function
# Recursively check each indices in string
# s is the input string
# idx is the current index 
def f(s, idx=0):
    # The algorithm is
    # We first list the vowels
    # Take their all indices in string
    # Take the absolute difference of the current position with the vowel indices
    # Take the minimum
    # Print
    print min(
              abs(index - idx) 
              for vowel in "aeiouAEIOU" 
              if vowel in s for index, char in enumerate(s) 
              if char == vowel
    )
    # Then check if current index+1 is less than the string length (basically check if we are out of the string)
    # If then we make a recursive call to go to next index
    # If not we short circuit to break the boolean chain and break out of the function
    idx + 1 < len(s) and f(s, idx + 1)
```
[Try it online!](https://tio.run/##bVNNT8MwDL33V1jj0oohAUfEDhw4cAIhEOc0dVZraTIl6T5@/bDTlm4TlfoR@71n5zndHlPr3ePpdAOfaNVOuQSmdzqRd4XEdB8i7dAeQbeoN4BKt0CuIY2R3xBTILdmKK8ipBY5uO3THKfmMGVYKyAXYDoeoCgaNGDKuBTM6r56Kgrg6wa@GKvs2gdKbcfkMfyDYCjEBJb4IYI7v0c7pb/UBiVKgcn2nx4vYaDq6G2fEBoyBrkxjeDNRaNbH0mcgD13MlectK8VO3LU9d0Y/uCiadjSVj4lXeblfHEP5eDGnZhQwVXe@PBXEhYKyfcvr2/v34trIJkZFzMtyy55akq@AV3fYVAJy1j9Q86w1WoQyenqbBpuHL4Az2d4@yCjtRhlvsplEwazOejW7FlZq0ia53GcJfbsfWCv@ZSMfg@caiz4loNOcJ1YqyBMxxBECpKHtZenw8PYyUx1Pgkztj4k0BR0T0mwdUC1ydVq7y0q2ZNiY5RrxtxZQ3@/QNaVI3wLD/AsuxL/hDMdXMlUJ1MuVK0buRdVcbE6/QI "Python 2 – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 89 bytes
```
sub{$n=1e9;$n=$_?$n:0,$_=$_<$n?$_:$n++for reverse@r=map$n=/[aeiou]/i?0:$n+1,pop=~/./g;@r}
```
[Try it online!](https://tio.run/##1ZZNT8JAEIbv/IpJs1gKi21FVKi15eDBmMhFT0CaolsoH7vrtvgRgn@97pZKSNR7O9lOp@kenpl3ZrOciFU3Q5GbJZvpFlHXJj1HvlDgIdq3MApkeI2oh4I@oq1WxAQI8kZEQnzhrkMu95qjkMRsMzFjz1KbbMwZd7/MU3Pm@GKXOVBlq8mUGxXGV26khco0cG/AwkdrgiuCP31@Uc9PBjaGs9wf4k4pUynwkznjnIic/pi7CEqrQoGfc5e@Vf7FH4SD8JbckSEZPP0egT9XKZIt8GXbR7P5YrlaU5bj26pzJGUPwxWGSwwXGLoYzuUQHMZiUgJ8Y1vpc1@59WcDJanAPvnghuujwKkYPvgzlronKMrzMJzKVV8WHiOZg6EuG7BgMW3oWMdSCgOPlSzSy99OCfG5iGkagVZv290E4D2kqVtvdywZg1JlH9eTMdVwGcuvLO9@yFUAJcM@BvKaf4EHOlvq0Ae92Ww@DB9heK@XQIrartJXzuwb "Perl 5 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 69 bytes
```
->s{w=s.size;s.chars.map{|c|w=[w+=1,s=~/[aeiou]/i||w].min;s[0]='';w}}
```
[Try it online!](https://tio.run/##bY8/D4IwEMV3P0WDA4NYQEdSEwYHJyenpkPBIlWBhoY0SvGrV/5UdPDy7nK593tJWzfJw2TIrHeyVUhCyZ8skjDNaS1hQUWrU60QVisUehK9fEwZrxric60VgQUvI4kDglw3Ul1nBMiwQxOapL3OQ2fjuDhkMXlDOQQsAQ488NXHtqmZCD2wGee8by0q80oIVk/kL2MXi/W@rR6zt5jGdM8O7Mji05@3/JWNjp/Jr7d7UVZD1LwB "Ruby – Try It Online")
### Break it down bro
```
->s{w=s.size;
```
Initialize with the worst case (will never happen)
```
    s.chars.map{|c|
```
For every character of the input string
```
        w=[w+=1,s=~/[aeiou]/i||w].min;
```
The value is the minimum between the position of the next vowel in the string (if any) and the previous value incremented by one.
```
            s[0]='';w}}
```
Cut the first character of the string, output the current value.
[Answer]
# [Python3](https://www.python.org/), 198 bytes
Golfed:
```
def f(s):
 v='aeiouAEIOU';l=[];r=[];L=R=len(s:=s.lower())-2
 for i in range(R+2):l.append(L:=0if s[i]in v else L+1);r.append(R:=0if s[~i]in v else R+1)
 return[min(l[x],r[~x])for x in range(len(s))]
```
  
removed 42 bytes by removing whitespace (thank you Aaron Miller)
  
removed 77 bytes shortened variable names(thank you Browncat Programs)
  
removed 43 bytes by implementing Aaron Miller's solution(thank you Aaron Miller)
  
Non-golfed:
```
def dTNV(s):
 s=s.lower()
 left_min=[]
 right_min=[]
 distl=distr=len(s)-2
 for i in range(len(s)):
  distl=0 if s[i] in 'aeiouAEIOU' else distl+1
  distr=0 if s[-(i+1)] in 'aeiouAEIOU' else distr+1
  left_min.append(distl)
  right_min.append(distr)
 return [min(left_min[i],right_min[-(i+1)]) for i in range(len(s))]
```
[Answer]
# [Python 3](https://docs.python.org/3/), 174 bytes
```
def f(s):
	o=[]
	for c,l in enumerate(s):
		i,j=c,0
		while 1:
			if i in range(len(s))and s[i]in'aeiouAEIOU':
				o+=[abs(c-i)]
				break
			j+=1
			i+=j*(j%2*2-1)
	return o
```
[Try it online!](https://tio.run/##NY2xisMwEERr6SvUHJFiB865LqDCRYpUqVIZF7K9ildxVkKWOe7rfZaPG1gYZh6z4SeNnr7WdQArrJzVhTOvm5Yz66Poy0kgCaDlDdEk@OsZlk735efmvkecQFQ5ZGgFZjoaeoKcgDZaGRrE3GCLdDCAfqmvt/vjsPPMF7ox3Sz7E6p2T7oI5pWdK3S1bxbaHaX7OB/Pp0pxFiEtkYRf/x@HiJSklUhhSVIptZosbrp@yMfn0YcAkfPa1OYKN7hD/eBbY5@je01v8r8 "Python 3 – Try It Online")
---
# [Python 3](https://docs.python.org/3/), 82 bytes
```
lambda s:[min(abs(s.index(v)-s.index(l))for v in s if v in'aeiouAEIOU')for l in s]
```
[Try it online!](https://tio.run/##NcmxDoIwFIXhvU/RjXbQxLiROHRgYGJiUoeL3Nqr5bahgPr0VUg8yUn@5IufyQU@Znu6ZA9D14NM5XkgVtAllfbEPb7Vonf/9FrbMMpFEsskyW5VAFKYTVU3bbGx3/iaX448ykMZR@JJWUUc50lprTOsE9Dd@vUiuRAjjkIYMFBhjQ2aVvzE3t3j6QcOXw "Python 3 – Try It Online")
As [xnor](https://codegolf.stackexchange.com/users/20260/xnor) pointed out, this doesn't work when a vowel appears multiple times in the string. The version above is longer but works when a vowel appears multiple times in the string.
[Answer]
## C++20, ~~145~~ 141 bytes (+17 bytes with a necessary #include +3 bytes for the general case with `int` instead of `char`)
One can use the function (in strict C++ language, it is a function template that can be turned into a function by substituting `auto s` by `std::string s` adding another 7 bytes)
```
auto f(auto s){int c=63,p=0;auto r=s;for(int i:s){for(int x:"AOEUI")c=i-x&~32?c:0;r[p++]=c++;}for(;--p>=0;)r[p]=r[p]<=c++?c=r[p]:c;return r;}
```
together with `std::vector<int>` or `std::string`, which requires the corresponding header to be included (`#include<string>` or `#include<vector>` = 16 bytes code + 1 byte line break).
```
auto f(auto s){
        auto r=s; // r: output (same type and length as s)
        int c=63,p=0; //c: distance counter, p: position in r
        //iterate forwards counting distance from previous vowel (or c+distance from beginning if vowel not yet found) and store it in r
        for(int i:s) {
                for(int x:"AOEUI") {
                        if(!((i-x)&(~32))) c=0; //set c to zero if c is a vowel (assuming ASCII)
                        //i-x == [ 0:upper case, 32:lower case]
                        //(i-x)&(~32) == [ false:i==x ignoring case, true:else ]
                }
                r[p++]=c++;
        }
        //iterate backwards counting distance and store lower value from both iterations in r
        for(--p;p>=0;--p) {
                if(r[p]<=c) {
                        c=r[p];
                } else {
                        r[p]=c;
                }
                ++c;
        }
        return r;
}
```
### `char` and `int` case
In the `char` case we assume that the input is not longer than 63 bytes. Then the initial value `c=63` will not cut off the distance even in cases where the vowel is at the end. It is also small enough not to lead to integer wrap-around, when the type of the elements of the data is signed char (-128..127).
If we want to have the general case for `int`egers, we need to initialize `c` with a larger value. In that case we substitute
```
int c=63,p=0;
```
by
```
int c=-1/4u,p=0;
```
adding **3 more bytes**. The signed number -1 corresponds to the largest unsigned integer. Dividing it by unsigned four (4u) converts the -1 to unsigned integer and reduces the value to the middle of the positive signed-integer range.
To cover both cases (`char` up to 63 bytes and longer `int` sequences) one can use
```
int c=size(s),p=0;
```
which would **add 5 bytes** compared to the `char` case.
### Usage example:
```
#include<iostream>
#include<string>
#include<vector>
auto f(auto s){int c=63,p=0;auto r=s;for(int i:s){for(int x:"AOEUI")c=i-x&~32?c:0;r[p++]=c++;}for(;--p>=0;)r[p]=r[p]<=c++?c=r[p]:c;return r;}
int main() {
        std::string result_str=f(std::string("abcdAbcd"));
        std::vector<int> result_vec=f(std::vector<int>({'a','b','c','d','A','b','c','d'}));
        std::cout << "std::string: ";
        for(int i:result_str) std::cout << i << " ";
        std::cout << std::endl;
        std::cout << "std::vector<int>: ";
        for(int i:result_vec) std::cout << i << " ";
        std::cout << std::endl;
        return 0;
}
```
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~32~~ 31 bytes
Not a very optimal solution because I couldn't get the short function defintion using the L command. Feel free to help me out here
## Code
```
DtZJrZ0R.ehSmadksmxdcJ1"aeiou"J
```
## Big-Pyth Version
```
def
  tail
  zero-var
  implicit-assign
    auto-var
    lower
      zero-var
      0
  return
    enumerate-map
      head
        sorted
          map
            absolute-difference
              map-var
              enumerate-map-ind
            flatten-once
              map
                ind-all-occurrences
                  map-var
                  chop-into-size-n
                    auto-var
                    1
                str-start aeiou str-end
      auto-var
```
[Try it online!](https://tio.run/##K6gsyfj/36UkyqsoyiBILzUjODcxJbs4tyIl2ctQKTE1M79Uyet/VlJuSYpe1f9EEOBKTEpOAWGu4oz8goLUIi4ux0THRNdUz1T/VMdQLqBMWnpGVnZObl4@AA)
[Translation Link](https://github.com/Hydrazer/pyth-programs/blob/main/zz_makeProgram/z_big-pyth.py)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 27 bytes
feel free to golf down my terrible husk
had to shift the line numbers by 1 to be able to run all the test cases correctly
```
₃W₂m_¹ŀ
#"aeiou
mλ▼mλa-²⁰)²
```
first line: `₃W₂m_¹ŀ`
```
         -- implicit parameter ⁰ (last argument)
      ŀ  -- get the indices of the list (1 to len(list))
   m_¹   -- map lowercase on a copy of last argument
 W₂m_¹   -- filter by line function 2 and return indicies of truthy results
₃W₂m_¹ŀ  -- call line function 3 with two arguments (W₂m_¹ & ŀ)
```
second line: `#"aeiou`
```
         -- implicit parameter ⁰ (last argument)
 "aeiou  -- string "aeiou"
#"aeiou  -- get amount of occurences in list
```
third line: `mλ▼mλa-²⁰)²`
```
             -- implicit parameters ⁰ & ² (last and second last argument)
mλ           -- map over implicit last parameter (ŀ) 
   mλ    )²  -- map over the second last parameter
   mλ -²⁰)²  -- get the difference between the last parameter (defined in this scope) and second last parameter (defined from the first lambda)
   mλa-²⁰)²  -- get the absolute value
  ▼mλa-²⁰)²  -- get the minimum of that list
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8f@jpubwR01NufGHdh5t4FJWSkzNzC/lyj23@9G0PUAyUffQpkeNGzQPbfr//3@0UiIIKOkoJSYlp4AwkFmckV9QkFoEZAGRY6JjomuqZ6p/qmMokAtUkZaekZWdk5uXrxQLAA)
[Answer]
# Excel, 198 bytes
```
=LET(x,LEN(A1),a,SEQUENCE(x),b,IFERROR(FIND(MID(A1,a,1),"aeiouAEIOU")^0*a,99999),d,SEQUENCE(x^2,,x),e,MOD(d,x)+1,f,INT(d/x),g,INDEX(ABS(b-TRANSPOSE(a)),e,f),IF(A1="","",FILTER(SORTBY(g,f,,g,),e=1)))
```
[Link to Spreadsheet](https://1drv.ms/x/s!AkqhtBc2XEHJnHIFCo0kl7Qdhyc6?e=CEKe1f)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ā©žMIlSåƶ0K®.xα
```
Input as a list of characters.
[Try it online](https://tio.run/##yy9OTMpM/f//SOOhlUf3@XrmHF56bJuB96F1ehXnNv7/H61UrKSjlAHE@UBcAMWpQFykFAsA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaVLcOj/I42HVh7d5xuRc3jpsW0G3ofW6VWc2/j/9Byd/9FKiSCgpKOUmJScAsJAZnFGfkFBahGQBUSOiY6Jrqmeqf6pjqFALlBFWnpGVnZObl6@UiwA).
**Explanation:**
```
ā               # Push a list in the range [1, (implicit) input-length]
 ©              # Store it in variable `®` (without popping)
  žM            # Push builtin "aeiou"
    I           # Push the input-list of characters
     l          # Convert each character to lowercase
      å         # Check for each if it's in the vowel-string
       ƶ        # Multiply each by its 1-based index
        0K      # Remove all 0s
          ®     # Push the [1, length] list from variable `®`
           .x   # Get for each index the closest vowel-index
             α  # Get the absolute difference of these with the indices
                # (after which the result is output implicitly)
```
[Answer]
# [Arturo](https://arturo-lang.io), 69 bytes
```
$->s[i:0map s=>[min map match.bounds s{(?i)[aeiou]}'x->abs-x\0i'i+1]]
```
[Try it](http://arturo-lang.io/playground?cHckZW)
```
$->s[                                  ; a function taking an argument s
    i:0                                ; assign 0 to i
    map s=>[                           ; map over s
        min                            ; minimum value in a list
        map                            ; map over...
        match.bounds s{(?i)[aeiou]}    ; the indices of the vowels in s
        'x->                           ; ...and assign current element t x
            abs                        ; absolute value
            -                          ; subtract
            x\0                        ; first elt of x (because match.bounds returns range)
            i                          ; and i
            'i+1                       ; increment i
    ]                                  ; end map
]                                      ; end function
```
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 8 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
Żı$ṃV-AM
```
#### Explanation
```
Żı$ṃV-AM  # Implicit input
Żı        # Map over the length range:
  $ṃV     # Indices of vowels in the input
     -AM  # Minimum of absolute differences
          # Implicit output
```
#### Screenshot
[![Screenshot](https://i.stack.imgur.com/shzn9m.png)](https://i.stack.imgur.com/shzn9.png)
]