Whale Talk expand functionality

Hi! I’m trying to expand the functionality of my code for the Whale Talk exercise. What I want to do is the following.

  1. Remove all consonants from the input text, double the ‘E’ and ‘U’ letters (as per the project’s instructions)

The expanded functionality is
2. Maintain the spacings between words.
3. If a spacing appears at the start or the end of the translated text, remove it (for example if the first word is ‘my’, the code will not register the word and then record a space as the first entry into my resultArray array.
4. Similar to #3, if 2 spacings appear next to each other, delete one of the spacings.

What Im expecting to result from my code is:
The phrase: “hello to all of my friends” translates to “EEO O A O IEE”

However what I’m getting from my code is:
The phrase: “hello to all of my friends” translates to "EEO O A O "

let input = 'hello to all of my friends'; const vowels = ['a','e','i','o','u',' ','!']; let resultArray = [] for (i = 0; i < input.length; i++) { for (v = 0; v < vowels.length; v++) { if (input[i] === vowels[v]) { if (vowels[v] === 'e') { resultArray.push(vowels[v], vowels[v]) } else if (vowels[v] === 'u') { resultArray.push(vowels[v], vowels[v]) } else resultArray.push(vowels[v]) } } } for (s = 0; s < resultArray.length; s++) { if (s === 0 && resultArray[s] === ' ') { resultArray.shift } else if (s > 0 && resultArray[s] === ' ' && resultArray[s-1] === ' ') { resultArray.splice(s,s) } else if (s === resultArray.length - 1 && resultArray[s] === ' ') { resultArray.pop } } console.log(`The phrase: "${input}" translates to "${resultArray.join('').toUpperCase()}"`);