Program to make vowels in string uppercase and change letters to next letter in alphabet (i.e. z->a) in JavaScript


We are required to write a JavaScript function that takes in a string as the only input.

The function should construct a new string based on the input string in which all the vowels should be uppercased and change each alphabet to the corresponding next alphabet.

For example − If the input string is −

const str = 'newString';

Therefore, the output for the above input should look like this −

const output = 'oExSusIoh';

Example

The code for this will be −

const str = 'newString';
const capitiliseAndMove = (str = '') => {
   let s = '';
   s = str.replace(/[a−z]/g, function(c) {
      return 'aeiou'.indexOf(c) > −1
         ? c.toUpperCase()
         : String.fromCharCode(Math.max(c.charCodeAt(0) % 122 + 1, 97));
   });
   return s;
};
console.log(capitiliseAndMove(str));

Output

And the output in the console will be −

oExSusIoh

Updated on: 23-Nov-2020

406 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements