
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Move All Vowels to the End of String Using JavaScript
Problem
We are required to write a JavaScript function that takes in a string. Our function should construct a new string in which all the consonants should hold their relative position and all the vowels should be pushed to the end of string.
Example
Following is the code −
const str = 'sample string'; const moveVowels = (str = '') => { const vowels = 'aeiou'; let front = ''; let rear = ''; for(let i = 0; i < str.length; i++){ const el = str[i]; if(vowels.includes(el)){ rear += el; }else{ front += el; }; }; return front + rear; }; console.log(moveVowels(str));
Output
smpl strngaei
Advertisements