Back to all solutions
#345 - Reverse Vowels of a String
Problem Description
Write a function that takes a string as input and reverse only the vowels of a string.
Solution
/**
* @param {string} s
* @return {string}
*/
var reverseVowels = function(s) {
const vowels = s.match(/[aeiou]/ig);
return s.replace(/[aeiou]/ig, () => vowels.pop());
};