Write a function that encodes a given sentence according to the following rules.
- For words that begin with a vowel (a, e, i, o, u), add "way".
- Otherwise, move all letters before the first vowel to the end and add "ay".
- For simplicity, no punctuation will be present in the inputs.
CODE TEMPLATE
function encode(str){
// write code here
}
console.log(encode("this is english language")); // "isthay isway englishway anguagelay"
console.log(encode("wall street journal"));// "allway eetstray ournaljay"
Please watch this video for a hint for the problem: