pigLatin
Translate the provided string to pig latin. Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an 'ay'. If a word begins with a vowel you just add 'way' to the end.
Examples
pigLatin('california') → 'aliforniacay'
pigLatin('glove') → 'oveglay'
pigLatin('algorithm') → 'algorithmway'
Starter code
function pigLatin(str) {
}
Complexity of the optimal solution
Time O(n), space O(n). The function performs searches and slicing operations on the string. These actions, along with creating the new result string, take time and space proportional to the input string's length (n).