What's missing in this code?
distanceToNearestVowel('hello'); // [1, 0, 1, 1, 0]
distanceToNearestVowel('world'); // [1, 0, 1, 2, 3]
distanceToNearestVowel('aaaaa'); // [0, 0, 0, 0, 0]
distanceToNearestVowel('bcdfg');
// [Infinity, Infinity, Infinity, Infinity, Infinity]
function distanceToNearestVowel(s)
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const distances = Array(s.length).
(Infinity);
let lastVowel =
;
for (let i = 0; i < s.length; i++)
if (vowels.has(s[i])) lastVowel = i;
distances[i] = i - lastVowel;
}
lastVowel = Infinity;
for (let i = s.length - 1; i >= 0; i--)
if (vowels.has(s[i])) lastVowel = i;
distances[i] = Math.
(distances[i], lastVowel - i);
}
return distances;
}
Type or select from these options