Skip to content

Instantly share code, notes, and snippets.

@dariodiaz
Last active April 5, 2021 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariodiaz/962336c9a57999a33455734a62419f6f to your computer and use it in GitHub Desktop.
Save dariodiaz/962336c9a57999a33455734a62419f6f to your computer and use it in GitHub Desktop.
[Reverse vowels] Leetcode challenge - Reverse vowels #leetcode #javascript #codinginterview
var reverseVowels = function (s) {
const arr = s.split("");
let left = 0, right = arr.length;
const vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'];
while (left < right) {
if (vowels.indexOf(arr[left]) === -1) {
left++;
continue;
}
if (vowels.indexOf(arr[right]) === -1) {
right--;
continue;
}
const temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
left++;
right--;
}
return arr.join("");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment