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
Updated on: 2020-11-21T05:51:39+05:30

429 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements