Last active
February 7, 2019 10:06
-
-
Save CodeDotJS/ce3f7491bd0b6c6c81dc70deb0cb5810 to your computer and use it in GitHub Desktop.
Function that takes a string as input and reverses only the vowels of a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const reverseVowelString = s => { | |
let str = s.split(''); | |
const voewls = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']; | |
const storeVowelsFromString = []; | |
for (let i = 0; i <= str.length - 1; i++) { | |
for (let j = 0; j <= voewls.length - 1; j++) { | |
if (str[i] === voewls[j]) { | |
storeVowelsFromString.push(str[i]); | |
str[i] = '_'; | |
} | |
} | |
} | |
const revStr = storeVowelsFromString.reverse(); | |
let index = 0; | |
return str.map(a => a === "_" ? revStr[index++] : a).join(''); | |
}; | |
console.log(reverseVowelString('ENTREPRENEURIAL')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment