Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Reversing vowels in a string JavaScript
We are required to write a JavaScript function that takes a string as input and reverse only the vowels of a string.
For example −
If the input string is −
const str = 'Hello';
Then the output should be −
const output = 'Holle';
The code for this will be −
const str = 'Hello'; const reverseVowels = (str = '') => {
const vowels = new Set(['a','e','i','o','u','A','E','I','O','U']);
let left = 0, right = str.length-1;
let foundLeft = false, foundRight = false;
str = str.split(""); while(left And the output in the console will be −
Holle
Advertisements
