Move string capital letters to front maintaining the relative order - JavaScript

We are required to write a JavaScript function that takes in a string with uppercase and lowercase letters. The function should return a string with all the uppercase letters moved to front of the string.

For example: If the input string is −

const str = 'heLLO woRlD';

Then the output should be −

const output = 'LLORDhe wol';

Example

Following is the code −

const str = 'heLLO woRlD';
const moveCapitalToFront = (str = '') => {
   let capitalIndex = 0;
   const newStrArr = [];
   for(let i = 0; i 

Output

Following is the output in the console −

LLORDhe wol
Updated on: 2020-09-16T09:35:03+05:30

361 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements