Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 2x 2x 2x 8x 4x 4x 1x 3x 3x 3x 3x 3x 2x | export default function reverseVowels(s: string): string {
const vowels = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
const sArr = s.split('')
for (let left = 0, right = sArr.length - 1; left < right;) {
if (vowels.has(sArr[left]) === false) {
left++
} else if (vowels.has(sArr[right]) === false) {
right--
} else {
const temp = sArr[left]
sArr[left] = sArr[right]
sArr[right] = temp
left++
right--
}
}
return sArr.join('')
}
|