If a word begins with a consonant, take the first consonant or consonant cluster and move to end of this word
the input of the program
blanket
sting
the output of the program
anketbl
ingst
First, you have to understand the meaning of the concept of "consonant cluster" linguistically: It's a consonant sequence sounds in a row. for example the word "blanket" is a consonant cluster with 2 consonant sounds "bl" .. and the word "strict" is a consonant cluster with 3 consonant sound "str" So, for words begin with consonant sounds, the sound should be moved to the end of this word. And the fetch will be based on the vowels that follow the consonant sound like this
function moveToEnd(string) {
// the variable index is going to store the first vowel found in the string
let index = 0;
for (let c of string) {
// Loop through the string until the first vowel has been found
if ('aeiou'.includes(c)) {
index = string.indexOf(c);
// once we find the index of the first vowel we jump out of the loop
break;
}
}
// the new String
return string.slice(index) + string.slice(0, index);
}
console.log(moveToEnd('blanket')) //---> output: ankletbl
let input = 'any string', vowel = [],consonant=[]
input.split('').forEach(e => {
if(/[aeiouwy]/gi.test(e)){
vowel.push(e)
}
else if(!/[aeiouwy]/gi.test(e)){consonant.push(e)}
})
console.log([...vowel,...consonant].toString())