Pig Latin
I was doing an exercise about pig latin which was and still confusing.
The moment I read the problem which I was given to solve I couldn’t understand what was needed from me to do in order to complete the challege and I didn’t even know how to start. That was the difficulties I faced and I had to ask for assistance from my peers, though they explained I still feel like I need more clarification on it.
Problem
I am supposed to provide string to pig latin, which takes the first conssonat cluster of an English word, moves it to the end of the word and suffixes an “ay” and if a word begins with a vowel I just add “way” to the end.
Solution Before assistance
I was planning to use a for-loop, for it to iterate through and push the first character to the end.Each an everytime it iterates and doesn’t find a vowel it should move that character to the end.
Solution
I applied the charAt(0) method to look for the character at the index which is specified in a string or array. && the length should be less or equal to 5 characters.
On the if statement I am checking if the character exists from vowels, I assigned str and sliced the first charater to place it at the end and add the “ay” after it has pushed the first character and I also sliced another character inorder to get to a vowel for another tests.
On the else if statement I looked for the index of not -1 which means the first index should be pushed by the ‘way’ at the end of the word.
On the last else if statement I again searched for the index and which is strickly equal to -1 and the length should be greater than 5. I sliced the first character and added ‘ay’ at the end after it pushed the last character which doesn’t match the vowels.
Experience
I was able to recall other things the moment I was helped by my peers and the way we discussed things together. I was able to also to suggest, though the code its a bit confusing itself, hopefully I will find other ways to solve it better.