Given an array of characters, return the array with every vowel doubled. For example:
**/Constraints
The challenge in this problem is in meeting its (arbitrary) constraints:
Do not convert into strings or manipulate strings at all.
Do not create any other data structures.
In particular, don't instantiate a new array.
The big-O of the solution should be O(n). **/
let vowelDoubler = (letters) => {
let wordLength = letters.length;
let vowels = ['a', 'e', 'i', 'o', 'u'];
let numVowel = 0;
//count vowels
for (let i=0; i < wordLength; i++) {
if(vowels.includes(letters[i])) {
numVowel++
}
}
let originalLength = letters.length - 1;
wordLength += numVowel - 1;
for(let i=wordLength; i > 0; i--) {
letters[i] = letters[originalLength];
if(vowels.includes(letters[i])) {
i--;
letters[i] = letters[originalLength];
}
originalLength--;
}
return letters
}